HandlerList { public synchronized void register(RegisteredHandler<? super T> handler) { final EventPriority priority = handler.meta().priority(); if(handlerslots.get(priority).contains(handler)) { throw new IllegalStateException("Event handler " + handler + " is already registered at priority " + priority); } handlers = null; handlerslots.get(priority).add(handler); } HandlerList(); static void bakeAll(); static void unregisterAll(); static void unregisterAll(Plugin plugin); static void unregisterAll(Listener listener); static void unregisterAll(Predicate<RegisteredHandler<?>> filter); synchronized void register(RegisteredHandler<? super T> handler); synchronized void register(RegisteredListener listener); void registerAll(Collection<RegisteredHandler<? super T>> handlers); synchronized void unregister(RegisteredHandler<? super T> handler); synchronized void unregister(Plugin plugin); synchronized void unregister(Predicate<? super RegisteredHandler<? super T>> filter); synchronized void unregister(Listener listener); void bake(); RegisteredHandler<? super T>[] getRegisteredListeners(); static ArrayList<RegisteredListener> getRegisteredListeners(Plugin plugin); @SuppressWarnings("unchecked") static ArrayList<HandlerList> getHandlerLists();  }
@Test public void duplicateRegistration() throws Throwable { HandlerList list = Event.getHandlerList(TestEvent.class); CallableEventHandler<TestEvent> handler = CallableEventHandler.create(TestEvent.class, event -> {}); list.register(handler); assertThrows(IllegalStateException.class, () -> list.register(handler) ); }