Plugin Lifecycle
CorePlugin
Section titled βCorePluginβCorePlugin is the abstract base every plugin built on this framework extends. It owns the ServiceRegistry and drives the ModuleManager. The onEnable() and onDisable() methods are final so the framework always controls the startup/shutdown sequence.
onEnable() ββ printBanner() ββ onPreEnable() β override for work before modules start ββ ModuleManager.enableAll(modules()) ββ module[0].onEnable() ββ module[1].onEnable() ββ ... ββ onPostEnable() β override for work after all modules are up
onDisable() ββ onPreDisable() β override for work before modules stop ββ ModuleManager.disableAll() ββ module[n].onDisable() β reverse order ββ ... ββ ServiceRegistry.clear()Lifecycle hooks
Section titled βLifecycle hooksβOverride these in your plugin class for pre/post module work:
public class MyPlugin extends CorePlugin {
@Override protected void onPreEnable() { // runs before any module is started }
@Override protected void onPostEnable() { // runs after all modules are running }
@Override protected void onPreDisable() { // runs before any module is stopped }}Singleton access
Section titled βSingleton accessβCorePlugin maintains a static instance() method. Use it only when a direct reference cannot be passed (e.g. from a static context):
CorePlugin plugin = CorePlugin.instance();// or cast to your subclass:MyPlugin plugin = (MyPlugin) CorePlugin.instance();instance() returns null after the plugin has been disabled.
Service registry access
Section titled βService registry accessβThe ServiceRegistry is shared across all modules and is accessible from the plugin:
MessageService messages = plugin.services().get(MessageService.class);Inside a module that extends AbstractModule, use the shorthand:
MessageService messages = service(MessageService.class);The banner
Section titled βThe bannerβOverride banner() to customize what appears in the console on startup:
@Overrideprotected String[] banner() { return new String[]{ "", " MyPlugin v" + getPluginMeta().getVersion(), " Author: yourname", "" };}