cn.nukkit.plugin.RegisteredListener Java Examples

The following examples show how to use cn.nukkit.plugin.RegisteredListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public static ArrayList<RegisteredListener> getRegisteredListeners(Plugin plugin) {
    ArrayList<RegisteredListener> listeners = new ArrayList<>();
    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;
}
 
Example #2
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public static ArrayList<RegisteredListener> getRegisteredListeners(Plugin plugin) {
    ArrayList<RegisteredListener> listeners = new ArrayList<>();
    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;
}
 
Example #3
Source File: HandlerList.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public static ArrayList<RegisteredListener> getRegisteredListeners(Plugin plugin) {
    ArrayList<RegisteredListener> listeners = new ArrayList<>();
    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;
}
 
Example #4
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void unregister(Plugin plugin) {
    boolean changed = false;
    for (List<RegisteredListener> list : handlerslots.values()) {
        for (ListIterator<RegisteredListener> i = list.listIterator(); i.hasNext(); ) {
            if (i.next().getPlugin().equals(plugin)) {
                i.remove();
                changed = true;
            }
        }
    }
    if (changed) handlers = null;
}
 
Example #5
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public RegisteredListener[] getRegisteredListeners() {
    RegisteredListener[] handlers;
    while ((handlers = this.handlers) == null) {
        bake();
    } // This prevents fringe cases of returning null
    return handlers;
}
 
Example #6
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void bake() {
    if (handlers != null) return; // don't re-bake when still valid
    List<RegisteredListener> entries = new ArrayList<>();
    for (Map.Entry<EventPriority, ArrayList<RegisteredListener>> entry : handlerslots.entrySet()) {
        entries.addAll(entry.getValue());
    }
    handlers = entries.toArray(new RegisteredListener[entries.size()]);
}
 
Example #7
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void unregister(Listener listener) {
    boolean changed = false;
    for (List<RegisteredListener> list : handlerslots.values()) {
        for (ListIterator<RegisteredListener> i = list.listIterator(); i.hasNext(); ) {
            if (i.next().getListener().equals(listener)) {
                i.remove();
                changed = true;
            }
        }
    }
    if (changed) handlers = null;
}
 
Example #8
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void unregister(Plugin plugin) {
    boolean changed = false;
    for (List<RegisteredListener> list : handlerslots.values()) {
        for (ListIterator<RegisteredListener> i = list.listIterator(); i.hasNext(); ) {
            if (i.next().getPlugin().equals(plugin)) {
                i.remove();
                changed = true;
            }
        }
    }
    if (changed) handlers = null;
}
 
Example #9
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static void unregisterAll() {
    synchronized (allLists) {
        for (HandlerList h : allLists) {
            synchronized (h) {
                for (List<RegisteredListener> list : h.handlerslots.values()) {
                    list.clear();
                }
                h.handlers = null;
            }
        }
    }
}
 
Example #10
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public RegisteredListener[] getRegisteredListeners() {
    RegisteredListener[] handlers;
    while ((handlers = this.handlers) == null) {
        bake();
    } // This prevents fringe cases of returning null
    return handlers;
}
 
Example #11
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void bake() {
    if (handlers != null) return; // don't re-bake when still valid
    List<RegisteredListener> entries = new ArrayList<>();
    for (Map.Entry<EventPriority, ArrayList<RegisteredListener>> entry : handlerslots.entrySet()) {
        entries.addAll(entry.getValue());
    }
    handlers = entries.toArray(new RegisteredListener[0]);
}
 
Example #12
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void unregister(Listener listener) {
    boolean changed = false;
    for (List<RegisteredListener> list : handlerslots.values()) {
        for (ListIterator<RegisteredListener> i = list.listIterator(); i.hasNext(); ) {
            if (i.next().getListener().equals(listener)) {
                i.remove();
                changed = true;
            }
        }
    }
    if (changed) handlers = null;
}
 
Example #13
Source File: HandlerList.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static void unregisterAll() {
    synchronized (allLists) {
        for (HandlerList h : allLists) {
            synchronized (h) {
                for (List<RegisteredListener> list : h.handlerslots.values()) {
                    list.clear();
                }
                h.handlers = null;
            }
        }
    }
}
 
Example #14
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static void unregisterAll() {
    synchronized (allLists) {
        for (HandlerList h : allLists) {
            synchronized (h) {
                for (List<RegisteredListener> list : h.handlerslots.values()) {
                    list.clear();
                }
                h.handlers = null;
            }
        }
    }
}
 
Example #15
Source File: HandlerList.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public RegisteredListener[] getRegisteredListeners() {
    RegisteredListener[] handlers;
    while ((handlers = this.handlers) == null) {
        bake();
    } // This prevents fringe cases of returning null
    return handlers;
}
 
Example #16
Source File: HandlerList.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void bake() {
    if (handlers != null) return; // don't re-bake when still valid
    List<RegisteredListener> entries = new ArrayList<>();
    for (Map.Entry<EventPriority, ArrayList<RegisteredListener>> entry : handlerslots.entrySet()) {
        entries.addAll(entry.getValue());
    }
    handlers = entries.toArray(new RegisteredListener[entries.size()]);
}
 
Example #17
Source File: HandlerList.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void unregister(Listener listener) {
    boolean changed = false;
    for (List<RegisteredListener> list : handlerslots.values()) {
        for (ListIterator<RegisteredListener> i = list.listIterator(); i.hasNext(); ) {
            if (i.next().getListener().equals(listener)) {
                i.remove();
                changed = true;
            }
        }
    }
    if (changed) handlers = null;
}
 
Example #18
Source File: HandlerList.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public synchronized void unregister(Plugin plugin) {
    boolean changed = false;
    for (List<RegisteredListener> list : handlerslots.values()) {
        for (ListIterator<RegisteredListener> i = list.listIterator(); i.hasNext(); ) {
            if (i.next().getPlugin().equals(plugin)) {
                i.remove();
                changed = true;
            }
        }
    }
    if (changed) handlers = null;
}
 
Example #19
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public synchronized void unregister(RegisteredListener listener) {
    if (handlerslots.get(listener.getPriority()).remove(listener)) {
        handlers = null;
    }
}
 
Example #20
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void registerAll(Collection<RegisteredListener> listeners) {
    for (RegisteredListener listener : listeners) {
        register(listener);
    }
}
 
Example #21
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
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;
    handlerslots.get(listener.getPriority()).add(listener);
}
 
Example #22
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
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;
    handlerslots.get(listener.getPriority()).add(listener);
}
 
Example #23
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void registerAll(Collection<RegisteredListener> listeners) {
    for (RegisteredListener listener : listeners) {
        register(listener);
    }
}
 
Example #24
Source File: HandlerList.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public synchronized void unregister(RegisteredListener listener) {
    if (handlerslots.get(listener.getPriority()).remove(listener)) {
        handlers = null;
    }
}
 
Example #25
Source File: HandlerList.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public synchronized void unregister(RegisteredListener listener) {
    if (handlerslots.get(listener.getPriority()).remove(listener)) {
        handlers = null;
    }
}
 
Example #26
Source File: HandlerList.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public void registerAll(Collection<RegisteredListener> listeners) {
    for (RegisteredListener listener : listeners) {
        register(listener);
    }
}
 
Example #27
Source File: HandlerList.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
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;
    handlerslots.get(listener.getPriority()).add(listener);
}