Add support for IPostRegisterRunnable.

Allows to register with the generic instance registry for another class,
after component registration, with implementing this method.
This commit is contained in:
asofold 2016-06-16 00:04:38 +02:00
parent d521a99ffc
commit d5b45e53f9
3 changed files with 33 additions and 5 deletions

View File

@ -0,0 +1,15 @@
package fr.neatmonster.nocheatplus.components.registry.feature;
/**
* Call runPostRegister, after ordinary steps of component registration have
* taken place. This doesn't necessarily way for sub-component that register on
* the next tick.
*
* @author asofold
*
*/
public interface IPostRegisterRunnable {
public void runPostRegister();
}

View File

@ -15,7 +15,8 @@
package fr.neatmonster.nocheatplus.components.registry.feature;
/**
* Register this instance as generic instance (for the class of this instance).
* Register this instance as generic instance (for the class of this instance),
* once passed to a component registry that supports this.
*
* @author asofold
*

View File

@ -87,6 +87,7 @@ import fr.neatmonster.nocheatplus.components.registry.feature.DisableListener;
import fr.neatmonster.nocheatplus.components.registry.feature.IHoldSubComponents;
import fr.neatmonster.nocheatplus.components.registry.feature.INeedConfig;
import fr.neatmonster.nocheatplus.components.registry.feature.INotifyReload;
import fr.neatmonster.nocheatplus.components.registry.feature.IPostRegisterRunnable;
import fr.neatmonster.nocheatplus.components.registry.feature.IRegisterAsGenericInstance;
import fr.neatmonster.nocheatplus.components.registry.feature.JoinLeaveListener;
import fr.neatmonster.nocheatplus.components.registry.feature.MCAccessHolder;
@ -435,8 +436,9 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
/**
* Convenience method to add components according to implemented interfaces,
* like Listener, INotifyReload, INeedConfig.<br>
* For the NoCheatPlus instance this must be done after the configuration has been initialized.
* This will also register ComponentRegistry instances if given.
* For the NoCheatPlus instance this must be done after the configuration
* has been initialized. This will also register ComponentRegistry instances
* if given.
*/
@Override
public boolean addComponent(final Object obj) {
@ -446,8 +448,12 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
/**
* Convenience method to add components according to implemented interfaces,
* like Listener, INotifyReload, INeedConfig.<br>
* For the NoCheatPlus instance this must be done after the configuration has been initialized.
* @param allowComponentRegistry Only registers ComponentRegistry instances if this is set to true.
* For the NoCheatPlus instance this must be done after the configuration
* has been initialized.
*
* @param allowComponentRegistry
* Only registers ComponentRegistry instances if this is set to
* true.
*/
@Override
public boolean addComponent(final Object obj, final boolean allowComponentRegistry) {
@ -534,6 +540,12 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
if (added) {
allComponents.add(obj);
}
// Post register hooks.
if (obj instanceof IPostRegisterRunnable) {
((IPostRegisterRunnable) obj).runPostRegister();
}
return added;
}