Accessing variables from another class
Our MobEnhancer
class is growing in size. There is no need to place all of our code within a single class. Our one class is extending the JavaPlugin
class as well as implementing both the Listener
and CommandExecutor
interfaces. Our program may be easier to understand if we split these into three unique classes.
Create two new classes named MobSpawnListener
and MobEnhancerReloadCommand
. MobEnhancer
will still be your main class, so it will still extend JavaPlugin
. However, the two new classes will implement Listener
and CommandExecutor
, respectively. Move the appropriate methods to their new classes. That is, onMobSpawn
is an event handler, so it belongs within the Listener
class and onCommand
belongs within the CommandExecutor
class. When moving the methods, you will notice several errors that are introduced. This is because your methods no longer have access to the necessary methods and variables. Let us first address the
MobEnhancerReloadCommand
...