mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-06 18:50:54 +01:00
Add methods for checking if listeners are registered.
This commit is contained in:
parent
9ed8a150bc
commit
a564d676a0
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user