From a564d676a0799b339decea9372255320cb8ebaf5 Mon Sep 17 00:00:00 2001 From: asofold Date: Mon, 3 Dec 2012 17:34:56 +0100 Subject: [PATCH] Add methods for checking if listeners are registered. --- .../nocheatplus/event/GenericListener.java | 8 +++ .../nocheatplus/event/ListenerManager.java | 49 ++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/fr/neatmonster/nocheatplus/event/GenericListener.java b/src/fr/neatmonster/nocheatplus/event/GenericListener.java index d86646af..6194198e 100644 --- a/src/fr/neatmonster/nocheatplus/event/GenericListener.java +++ b/src/fr/neatmonster/nocheatplus/event/GenericListener.java @@ -205,4 +205,12 @@ public class GenericListener implements Listener, EventExecutor oldEntries[i] = null; } } + + /** + * If any methods are actually registered. + * @return + */ + public boolean hasListenerMethods() { + return entries.length > 0; + } } diff --git a/src/fr/neatmonster/nocheatplus/event/ListenerManager.java b/src/fr/neatmonster/nocheatplus/event/ListenerManager.java index eda76335..36bdfeb7 100644 --- a/src/fr/neatmonster/nocheatplus/event/ListenerManager.java +++ b/src/fr/neatmonster/nocheatplus/event/ListenerManager.java @@ -175,11 +175,58 @@ public class ListenerManager { * @param listener */ public void remove(Listener listener) { - for (EnumMap> prioMap : map.values()){ + for (Map> prioMap : map.values()){ for (GenericListener gl : prioMap.values()){ gl.remove(listener); } } } + /** + * Check if any GenericListeners are registered with Bukkit.
(To check if actually any listener methods are registered use: hasListenerMethods) + * @return + */ + public boolean hasListeners(){ + return !map.isEmpty(); + } + + /** + * Check if any GenericListeners are present that are registered. + * @return + */ + public boolean hasRegisteredListeners(){ + for (Map> prioMap : map.values()){ + for (GenericListener gl : prioMap.values()){ + if (gl.isRegistered()) return true; + } + } + return false; + } + + /** + * Check if any GenericListeners are present that are not yet registered. + * @return + */ + public boolean hasPendingListeners(){ + for (Map> prioMap : map.values()){ + for (GenericListener gl : prioMap.values()){ + if (!gl.isRegistered()) return true; + } + } + return false; + } + + /** + * Check if any methods are registered for listening. + * @return + */ + public boolean hasListenerMethods(){ + for (Map> prioMap : map.values()){ + for (GenericListener gl : prioMap.values()){ + if (gl.hasListenerMethods()) return true; + } + } + return false; + } + }