-
Notifications
You must be signed in to change notification settings - Fork 48
The Module Manager
You may have noticed that we are using Prison.get().getModuleManager()
to register our module with Prison. The ModuleManager
has a few other uses that can assist you in the development process. This guide will show you how use the module manager for a few different purposes.
To get a specific module by its name, you may use this approach:
Module module = Prison.get().getModuleManager().getModule("ModuleName");
If you wish to depend on a module, include it in your project dependencies and simply cast it like so.
TestModule testModule = (TestModule) Prison.get().getModuleManager().getModule("Test");
Note: Remember to add the module you are depending on to your Spigot
plugin.yml
or Sponge@Plugin
annotation to ensure they load in the correct sequence. If you don't do this, problems will occur when depending on other modules, just as they would when depending on any other plugins.
Module statuses are used to convey to both the user and Prison-Core that your module is not functioning normally. During the module enable process, the status of the module is null. After a successful enable, the status is automatically changed to "&aEnabled" (notice the color code).
If the status is not null after the enable()
method is called, then Prison-Core assumes something went wrong with the enable process and acts accordingly.
To set the status, do it like so:
@Override public void enable() {
if(somethingWrong) {
Prison.get().getModuleManager().setStatus(this.getName(), "&cError: Something wrong happened.");
return;
}
}
Notice that you may use color codes in this status message. Now, Prison will register the failed enable and print output such as this:
Notice that the status message is shown in the /prison modules
command output.
It's quite simple.
Prison.get().getModuleManager().enableModule(module); // Enable a module
Prison.get().getModuleManager().disableModule(module); // Disable a module