示例#1
0
 /**
  * Register a new listener in this handler list
  *
  * @param listener listener to register
  */
 public synchronized void register(RegisteredListener listener) {
   if (handlerslots.get(listener.getPriority()).contains(listener)) {
     throw new IllegalStateException(
         "This listener is already registered to priority " + listener.getPriority().toString());
   }
   handlers = null;
   if (listener.getPriority() == EventPriority.EXECUTOR && allowExecutor == false) {
     throw new IllegalStateException("an executor is not allowed for this event");
   }
   if (listener.getPriority() == EventPriority.EXECUTOR
       && handlerslots.get(EventPriority.EXECUTOR).isEmpty() == false) {
     throw new IllegalStateException("an executor is already registered for this event");
   }
   handlerslots.get(listener.getPriority()).add(listener);
 }
示例#2
0
 /**
  * Get a specific plugin's registered listeners associated with this handler list
  *
  * @param plugin the plugin to get the listeners of
  * @return the list of registered listeners
  */
 public static ArrayList<RegisteredListener> getRegisteredListeners(EventPlugin plugin) {
   ArrayList<RegisteredListener> listeners = new ArrayList<RegisteredListener>();
   synchronized (allLists) {
     for (HandlerList h : allLists) {
       synchronized (h) {
         for (List<RegisteredListener> list : h.handlerslots.values()) {
           for (RegisteredListener listener : list) {
             if (listener.getPlugin().equals(plugin)) {
               listeners.add(listener);
             }
           }
         }
       }
     }
   }
   return listeners;
 }
示例#3
0
 /**
  * Remove a listener from a specific order slot
  *
  * @param listener listener to remove
  */
 public synchronized void unregister(RegisteredListener listener) {
   if (handlerslots.get(listener.getPriority()).remove(listener)) {
     handlers = null;
   }
 }