/** * Registers all the events in the given listener class. * * @param listener - listener to register * @param plugin - plugin to register */ public void registerEvents(Listener listener, Plugin plugin) { if (!plugin.isEnabled()) throw new IllegalPluginAccessException( "Plugin attempted to register " + listener + " while not enabled"); // Just in case Bukkit decides to validate the parameters in the future EventExecutor nullExecutor = (arg0, arg1) -> { throw new IllegalStateException("This method should never be called!"); }; for (Entry<Class<? extends Event>, Set<RegisteredListener>> entry : plugin.getPluginLoader().createRegisteredListeners(listener, plugin).entrySet()) { Collection<RegisteredListener> listeners = entry.getValue(); Collection<RegisteredListener> modified = Lists.newArrayList(); // Use our plugin specific logger instead for (final RegisteredListener delegate : listeners) { RegisteredListener customListener = new RegisteredListener( delegate.getListener(), nullExecutor, delegate.getPriority(), delegate.getPlugin(), delegate.isIgnoringCancelled()) { @Override public void callEvent(Event event) throws EventException { try { delegate.callEvent(event); } catch (AuthorNagException e) { // Let Bukkit handle that one throw e; } catch (Throwable e) { customHandler(event, e); } } }; modified.add(customListener); } getEventListeners(getRegistrationClass(entry.getKey())).registerAll(modified); } }
public LoggedPluginManager(Plugin owner) { this(owner.getServer().getPluginManager()); }