Add methods for checking if listeners are registered.

This commit is contained in:
asofold 2012-12-03 17:34:56 +01:00
parent 9ed8a150bc
commit a564d676a0
2 changed files with 56 additions and 1 deletions

View File

@ -205,4 +205,12 @@ public class GenericListener<E extends Event> implements Listener, EventExecutor
oldEntries[i] = null;
}
}
/**
* If any methods are actually registered.
* @return
*/
public boolean hasListenerMethods() {
return entries.length > 0;
}
}

View File

@ -175,11 +175,58 @@ public class ListenerManager {
* @param listener
*/
public void remove(Listener listener) {
for (EnumMap<EventPriority, GenericListener<?>> prioMap : map.values()){
for (Map<EventPriority, GenericListener<?>> prioMap : map.values()){
for (GenericListener<?> gl : prioMap.values()){
gl.remove(listener);
}
}
}
/**
* Check if any GenericListeners are registered with Bukkit. <br>(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<EventPriority, GenericListener<?>> 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<EventPriority, GenericListener<?>> 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<EventPriority, GenericListener<?>> prioMap : map.values()){
for (GenericListener<?> gl : prioMap.values()){
if (gl.hasListenerMethods()) return true;
}
}
return false;
}
}