[BREAKING] Rename the new DisableListener to IDisableListener.

(Plus call in reverse order of registration.)
This commit is contained in:
asofold 2016-06-19 12:15:30 +02:00
parent d4acad924a
commit 92252a9dc4
9 changed files with 65 additions and 57 deletions

View File

@ -40,7 +40,7 @@ import fr.neatmonster.nocheatplus.checks.net.NetData;
import fr.neatmonster.nocheatplus.checks.net.NetDataFactory; import fr.neatmonster.nocheatplus.checks.net.NetDataFactory;
import fr.neatmonster.nocheatplus.compat.versions.ServerVersion; import fr.neatmonster.nocheatplus.compat.versions.ServerVersion;
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI; import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
import fr.neatmonster.nocheatplus.components.registry.feature.DisableListener; import fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener;
import fr.neatmonster.nocheatplus.components.registry.feature.INotifyReload; import fr.neatmonster.nocheatplus.components.registry.feature.INotifyReload;
import fr.neatmonster.nocheatplus.components.registry.feature.JoinLeaveListener; import fr.neatmonster.nocheatplus.components.registry.feature.JoinLeaveListener;
import fr.neatmonster.nocheatplus.config.ConfPaths; import fr.neatmonster.nocheatplus.config.ConfPaths;
@ -52,10 +52,11 @@ import fr.neatmonster.nocheatplus.utilities.StringUtil;
/** /**
* Quick and dirty ProtocolLib setup. * Quick and dirty ProtocolLib setup.
* @author dev1mc *
* @author asofold
* *
*/ */
public class ProtocolLibComponent implements DisableListener, INotifyReload, JoinLeaveListener, Listener { public class ProtocolLibComponent implements IDisableListener, INotifyReload, JoinLeaveListener, Listener {
// TODO: Static reference is problematic (needs a static and accessible Counters instance?). // TODO: Static reference is problematic (needs a static and accessible Counters instance?).
public static final int idNullPlayer = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class).registerKey("packet.flying.nullplayer"); public static final int idNullPlayer = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class).registerKey("packet.flying.nullplayer");

View File

@ -20,7 +20,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.ViolationData; import fr.neatmonster.nocheatplus.checks.ViolationData;
import fr.neatmonster.nocheatplus.components.registry.feature.DisableListener; import fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener;
import fr.neatmonster.nocheatplus.utilities.TickTask; import fr.neatmonster.nocheatplus.utilities.TickTask;
/** /**
@ -30,7 +30,7 @@ import fr.neatmonster.nocheatplus.utilities.TickTask;
* @author mc_dev * @author mc_dev
* *
*/ */
public class Improbable extends Check implements DisableListener{ public class Improbable extends Check implements IDisableListener{
private static Improbable instance = null; private static Improbable instance = null;

View File

@ -20,7 +20,7 @@ import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.components.registry.feature.DisableListener; import fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener;
import fr.neatmonster.nocheatplus.utilities.InventoryUtil; import fr.neatmonster.nocheatplus.utilities.InventoryUtil;
/** /**
@ -28,7 +28,7 @@ import fr.neatmonster.nocheatplus.utilities.InventoryUtil;
* @author mc_dev * @author mc_dev
* *
*/ */
public class Open extends Check implements DisableListener{ public class Open extends Check implements IDisableListener{
private static Open instance = null; private static Open instance = null;

View File

@ -16,11 +16,11 @@ package fr.neatmonster.nocheatplus.components;
/** /**
* @deprecated To be removed, use instead: * @deprecated To be removed, use instead:
* fr.neatmonster.nocheatplus.components.registry.feature.DisableListener * fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener
* @author asofold * @author asofold
* *
*/ */
@Deprecated @Deprecated
public interface DisableListener extends fr.neatmonster.nocheatplus.components.registry.feature.DisableListener { public interface DisableListener extends fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener {
} }

View File

@ -31,7 +31,7 @@ import fr.neatmonster.nocheatplus.logging.LogManager;
* ComponentRegistry: * ComponentRegistry:
* <li>Supported components: Listener, TickListener, PermStateReceiver, * <li>Supported components: Listener, TickListener, PermStateReceiver,
* INotifyReload, INeedConfig, IRemoveData, MCAccessHolder, ConsistencyChecker, * INotifyReload, INeedConfig, IRemoveData, MCAccessHolder, ConsistencyChecker,
* JoinLeaveListener, DisableListener</li> * JoinLeaveListener, IDisableListener</li>
* <li>ComponentRegistry instances will be registered as sub registries unless * <li>ComponentRegistry instances will be registered as sub registries unless
* you use the addComponent(Object, boolean) method appropriately.</li> * you use the addComponent(Object, boolean) method appropriately.</li>
* <li>IHoldSubComponents instances will be registered in the next tick * <li>IHoldSubComponents instances will be registered in the next tick

View File

@ -20,12 +20,13 @@ package fr.neatmonster.nocheatplus.components.registry.feature;
* @author asofold * @author asofold
* *
*/ */
public interface DisableListener { public interface IDisableListener {
/** /**
* Called in the plugin in onDisable, before all components get * Called in the plugin in onDisable in reversed order of registration,
* unregistered. This is meant for general data cleanup, there may be extra * before all components get unregistered. This is meant for general data
* registry cleanup stages for data sources and checks later on. * cleanup, there may be extra registry cleanup stages for data sources and
* checks later on.
*/ */
public void onDisable(); public void onDisable();

View File

@ -18,36 +18,37 @@ import java.util.Comparator;
/** /**
* Utilities for sorting out order. * Utilities for sorting out order.
* @author mc_dev * @author asofold
* *
*/ */
public class Order { public class Order {
/** /**
* Comparator for sorting SetupOrder. * Comparator for sorting SetupOrder.
*/ */
public static Comparator<Object> cmpSetupOrder = new Comparator<Object>() { public static Comparator<Object> cmpSetupOrder = new Comparator<Object>() {
@Override @Override
public int compare(final Object obj1, final Object obj2) { public int compare(final Object obj1, final Object obj2) {
int prio1 = 0; int prio1 = 0;
int prio2 = 0; int prio2 = 0;
final SetupOrder order1 = obj1.getClass().getAnnotation(SetupOrder.class); final SetupOrder order1 = obj1.getClass().getAnnotation(SetupOrder.class);
if (order1 != null) { if (order1 != null) {
prio1 = order1.priority(); prio1 = order1.priority();
} }
final SetupOrder order2 = obj2.getClass().getAnnotation(SetupOrder.class); final SetupOrder order2 = obj2.getClass().getAnnotation(SetupOrder.class);
if (order2 != null) { if (order2 != null) {
prio2 = order2.priority(); prio2 = order2.priority();
} }
if (prio1 < prio2) { if (prio1 < prio2) {
return -1; return -1;
} }
else if (prio1 == prio2){ else if (prio1 == prio2){
return 0; return 0;
} }
else { else {
return 1; return 1;
} }
} }
}; };
} }

View File

@ -50,7 +50,7 @@ import fr.neatmonster.nocheatplus.compat.versions.ServerVersion;
import fr.neatmonster.nocheatplus.components.registry.ComponentRegistry; import fr.neatmonster.nocheatplus.components.registry.ComponentRegistry;
import fr.neatmonster.nocheatplus.components.registry.feature.ComponentWithName; import fr.neatmonster.nocheatplus.components.registry.feature.ComponentWithName;
import fr.neatmonster.nocheatplus.components.registry.feature.ConsistencyChecker; import fr.neatmonster.nocheatplus.components.registry.feature.ConsistencyChecker;
import fr.neatmonster.nocheatplus.components.registry.feature.DisableListener; import fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener;
import fr.neatmonster.nocheatplus.components.registry.feature.ICanHandleTimeRunningBackwards; import fr.neatmonster.nocheatplus.components.registry.feature.ICanHandleTimeRunningBackwards;
import fr.neatmonster.nocheatplus.components.registry.feature.IHaveCheckType; import fr.neatmonster.nocheatplus.components.registry.feature.IHaveCheckType;
import fr.neatmonster.nocheatplus.components.registry.feature.INeedConfig; import fr.neatmonster.nocheatplus.components.registry.feature.INeedConfig;
@ -77,7 +77,7 @@ import fr.neatmonster.nocheatplus.utilities.StringUtil;
* *
*/ */
@SetupOrder(priority = -80) @SetupOrder(priority = -80)
public class DataManager implements Listener, INotifyReload, INeedConfig, ComponentRegistry<IRemoveData>, ComponentWithName, ConsistencyChecker, DisableListener{ public class DataManager implements Listener, INotifyReload, INeedConfig, ComponentRegistry<IRemoveData>, ComponentWithName, ConsistencyChecker, IDisableListener{
private static DataManager instance = null; private static DataManager instance = null;

View File

@ -86,7 +86,7 @@ import fr.neatmonster.nocheatplus.components.registry.DefaultGenericInstanceRegi
import fr.neatmonster.nocheatplus.components.registry.event.IGenericInstanceHandle; import fr.neatmonster.nocheatplus.components.registry.event.IGenericInstanceHandle;
import fr.neatmonster.nocheatplus.components.registry.feature.ComponentWithName; import fr.neatmonster.nocheatplus.components.registry.feature.ComponentWithName;
import fr.neatmonster.nocheatplus.components.registry.feature.ConsistencyChecker; import fr.neatmonster.nocheatplus.components.registry.feature.ConsistencyChecker;
import fr.neatmonster.nocheatplus.components.registry.feature.DisableListener; import fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener;
import fr.neatmonster.nocheatplus.components.registry.feature.IHoldSubComponents; import fr.neatmonster.nocheatplus.components.registry.feature.IHoldSubComponents;
import fr.neatmonster.nocheatplus.components.registry.feature.INeedConfig; import fr.neatmonster.nocheatplus.components.registry.feature.INeedConfig;
import fr.neatmonster.nocheatplus.components.registry.feature.INotifyReload; import fr.neatmonster.nocheatplus.components.registry.feature.INotifyReload;
@ -215,7 +215,7 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
/** Queued sub component holders, emptied on the next tick usually. */ /** Queued sub component holders, emptied on the next tick usually. */
protected final List<IHoldSubComponents> subComponentholders = new ArrayList<IHoldSubComponents>(20); protected final List<IHoldSubComponents> subComponentholders = new ArrayList<IHoldSubComponents>(20);
private final List<DisableListener> disableListeners = new ArrayList<DisableListener>(); private final List<IDisableListener> disableListeners = new ArrayList<IDisableListener>();
/** All registered components. */ /** All registered components. */
protected Set<Object> allComponents = new LinkedHashSet<Object>(50); protected Set<Object> allComponents = new LinkedHashSet<Object>(50);
@ -521,8 +521,8 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
joinLeaveListeners.add((JoinLeaveListener) obj); joinLeaveListeners.add((JoinLeaveListener) obj);
added = true; added = true;
} }
if (obj instanceof DisableListener) { if (obj instanceof IDisableListener) {
disableListeners.add((DisableListener) obj); disableListeners.add((IDisableListener) obj);
added = true; added = true;
} }
@ -613,8 +613,8 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
if (obj instanceof JoinLeaveListener) { if (obj instanceof JoinLeaveListener) {
joinLeaveListeners.remove((JoinLeaveListener) obj); joinLeaveListeners.remove((JoinLeaveListener) obj);
} }
if (obj instanceof DisableListener) { if (obj instanceof IDisableListener) {
disableListeners.remove((DisableListener) obj); disableListeners.remove((IDisableListener) obj);
} }
// Remove sub registries. // Remove sub registries.
@ -636,9 +636,9 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
* <ul> * <ul>
* <li>Prevent further registration. For now also disable listeners, though * <li>Prevent further registration. For now also disable listeners, though
* this might get shifted still.</li> * this might get shifted still.</li>
* <li><b>Call onDisable for DisableListener instances.</b> This includes * <li><b>Call onDisable for IDisableListener instances, in reversed
* clearing all data (Needs extensions for sorting by priority for * order of registration.</b> This includes clearing all data (Needs extensions for sorting
* DisableListener instances.).</li> * by priority for IDisableListener instances.).</li>
* <li>Random sequence of cleanup calls for other registries and logging * <li>Random sequence of cleanup calls for other registries and logging
* statistics.</li> * statistics.</li>
* <li>Call removeComponent for all registered components.</li> * <li>Call removeComponent for all registered components.</li>
@ -702,15 +702,18 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
if (verbose) { if (verbose) {
logManager.info(Streams.INIT, "onDisable calls (include DataManager cleanup)..."); logManager.info(Streams.INIT, "onDisable calls (include DataManager cleanup)...");
} }
// TODO: Sorting order + sort now (checks and data cleanup late, data manager last, allow plugins to access stuff before data is reset). // TODO: Reliable sorting order + sort now (checks and data cleanup late, data manager last, allow plugins to access stuff before data is reset).
for (final DisableListener dl : disableListeners) { final ArrayList<IDisableListener> disableListeners = new ArrayList<IDisableListener>(this.disableListeners);
Collections.reverse(disableListeners);
for (final IDisableListener dl : disableListeners) {
try { try {
dl.onDisable(); dl.onDisable();
} catch (Throwable t) { } catch (Throwable t) {
logManager.severe(Streams.INIT, "DisableListener (" + dl.getClass().getName() + "): " + t.getClass().getSimpleName() + " / " + t.getMessage()); logManager.severe(Streams.INIT, "IDisableListener (" + dl.getClass().getName() + "): " + t.getClass().getSimpleName() + " / " + t.getMessage());
logManager.severe(Streams.INIT, t); logManager.severe(Streams.INIT, t);
} }
} }
// (Component removal will clear the list, rather.)
// ExemptionManager cleanup. // ExemptionManager cleanup.
if (verbose) { if (verbose) {
@ -755,6 +758,8 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
if (verbose) { if (verbose) {
logManager.info(Streams.INIT, "Cleanup some mappings..."); logManager.info(Streams.INIT, "Cleanup some mappings...");
} }
// Remove IDisableListener instances.
disableListeners.clear(); // Just in case.
// Remove listeners. // Remove listeners.
listeners.clear(); listeners.clear();
// Remove config listeners. // Remove config listeners.