public void registerEvents(Listener l) { for (Map.Entry<Class<? extends Event>, Set<RegisteredListener>> entry : addMuffins(l).entrySet()) { try { getEventListeners(getRegistrationClass(entry.getKey())).registerAll(entry.getValue()); } catch (IllegalAccessException e) { server.Log("==!EVENT ERROR!=="); server.logError(e); } } }
private EventList getEventListeners(Class<? extends Event> type) { try { Method method = getRegistrationClass(type).getDeclaredMethod("getEventList"); method.setAccessible(true); return (EventList) method.invoke(null); } catch (Exception e) { server.Log("==!EVENT ERROR!=="); server.logError(e); return null; } }
public void callEvent(Event event) { EventList events = event.getEvents(); RegisteredListener[] listeners = events.getRegisteredListeners(); for (RegisteredListener listen : listeners) { try { listen.execute(event); } catch (Exception e) { server.Log("==!EVENT ERROR!=="); server.logError(e); } } }