[DOC] Документация по новой системе модулей

This commit is contained in:
Gravit 2019-08-28 16:37:59 +07:00
parent a6e4359216
commit 0920fe18f4
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
2 changed files with 56 additions and 0 deletions

View file

@ -24,6 +24,13 @@ public LauncherModuleInfo getModuleInfo() {
return moduleInfo; 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 public enum InitStatus
{ {
CREATED, CREATED,
@ -58,6 +65,11 @@ public LauncherModule setInitStatus(InitStatus initStatus) {
return this; return this;
} }
/**
* The internal method used by the ModuleManager
* DO NOT TOUCH
* @param context Private context
*/
public void setContext(LauncherModulesContext context) public void setContext(LauncherModulesContext context)
{ {
if(this.context != null) throw new IllegalStateException("Module already set 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.modulesConfigManager = context.getModulesConfigManager();
} }
/**
* This method is called before initializing all modules and resolving dependencies.
* <b>You can</b>:
* Use to Module Manager
* Add custom modules not described in the manifest
* Change information about your module or modules you control
* <b>You can not</b>:
* Use your dependencies
* Use API Launcher, LaunchServer, ServerWrapper
* Change the names of any modules
*/
public void preInit() { public void preInit() {
//NOP //NOP
} }
/**
* Basic module initialization method
* <b>You can</b>:
* Subscribe to events
* Use your dependencies
* Use provided initContext
* Receive modules and access the modules internal methods
* <b>You can not</b>:
* Modify module description, dependencies
* Add modules
* Read configuration
* @param initContext <tr>null</tr> on module initialization during boot or startup
* Not <tr>null</tr> during module initialization while running
*/
public abstract void init(LauncherInitContext initContext); public abstract void init(LauncherInitContext initContext);
/**
* Registers an event handler for the current module
* @param handle your event handler
* @param tClass event class
* @param <T> event type
* @return true if adding a handler was successful
*/
protected <T extends Event> boolean registerEvent(EventHandler<T> handle, Class<T> tClass) protected <T extends Event> boolean registerEvent(EventHandler<T> handle, Class<T> tClass)
{ {
eventMap.put(tClass, handle); eventMap.put(tClass, handle);
return true; return true;
} }
/**
* Call the handler of the current module
* @param event event handled
* @param <T> event type
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public final <T extends Event> void callEvent(T event) public final <T extends Event> void callEvent(T event)
{ {

View file

@ -23,5 +23,12 @@ default <T extends LauncherModule> boolean containsModule(Class<? extends T> cl
ClassLoader getModuleClassLoader(); ClassLoader getModuleClassLoader();
<T extends LauncherModule> T getModule(Class<? extends T> clazz); <T extends LauncherModule> T getModule(Class<? extends T> clazz);
<T extends LauncherModule> T findModule(Class<? extends T> clazz, Predicate<Version> versionPredicate); <T extends LauncherModule> T findModule(Class<? extends T> clazz, Predicate<Version> 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 <T> event type
*/
<T extends LauncherModule.Event> void invokeEvent(T event); <T extends LauncherModule.Event> void invokeEvent(T event);
} }