diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java index 3f197446..0323b629 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java @@ -24,6 +24,13 @@ public LauncherModuleInfo getModuleInfo() { return moduleInfo; } + + /** + * Module initialization status at the current time + * CREATED - Module status immediately after loading + * INIT - The state of the module during the execution of the method init() + * FINISH - Status of the module after initialization + */ public enum InitStatus { CREATED, @@ -58,6 +65,11 @@ public LauncherModule setInitStatus(InitStatus initStatus) { return this; } + /** + * The internal method used by the ModuleManager + * DO NOT TOUCH + * @param context Private context + */ public void setContext(LauncherModulesContext context) { if(this.context != null) throw new IllegalStateException("Module already set context"); @@ -66,19 +78,56 @@ public void setContext(LauncherModulesContext context) this.modulesConfigManager = context.getModulesConfigManager(); } + /** + * This method is called before initializing all modules and resolving dependencies. + * You can: + * Use to Module Manager + * Add custom modules not described in the manifest + * Change information about your module or modules you control + * You can not: + * Use your dependencies + * Use API Launcher, LaunchServer, ServerWrapper + * Change the names of any modules + */ public void preInit() { //NOP } + /** + * Basic module initialization method + * You can: + * Subscribe to events + * Use your dependencies + * Use provided initContext + * Receive modules and access the module’s internal methods + * You can not: + * Modify module description, dependencies + * Add modules + * Read configuration + * @param initContext null on module initialization during boot or startup + * Not null during module initialization while running + */ public abstract void init(LauncherInitContext initContext); + /** + * Registers an event handler for the current module + * @param handle your event handler + * @param tClass event class + * @param event type + * @return true if adding a handler was successful + */ protected boolean registerEvent(EventHandler handle, Class tClass) { eventMap.put(tClass, handle); return true; } + /** + * Call the handler of the current module + * @param event event handled + * @param event type + */ @SuppressWarnings("unchecked") public final void callEvent(T event) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesManager.java index ee11b62a..78983692 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesManager.java @@ -23,5 +23,12 @@ default boolean containsModule(Class cl ClassLoader getModuleClassLoader(); T getModule(Class clazz); T findModule(Class clazz, Predicate versionPredicate); + + /** + * Invoke event processing for all modules. + * Event processing is carried out in the order of the modules in the list (sorted by priority) + * @param event event handled + * @param event type + */ void invokeEvent(T event); }