/** * Unregisters a listener for the IPluginEvent callback event. * * @param listener Listener to be unregistered. */ public void unregisterListener(IPluginEventListener listener) { if (pluginEventListeners2 != null && pluginEventListeners2.contains(listener)) { pluginEventListeners2.remove(listener); listener.onPluginEvent(new PluginEvent(this, PluginAction.UNSUBSCRIBE)); } }
/** * Registers a listener for the IPluginEventListener callback event. If the listener has already * been registered, the request is ignored. * * @param listener Listener to be registered. */ public void registerListener(IPluginEventListener listener) { if (pluginEventListeners2 == null) { pluginEventListeners2 = new ArrayList<>(); } if (!pluginEventListeners2.contains(listener)) { pluginEventListeners2.add(listener); listener.onPluginEvent(new PluginEvent(this, PluginAction.SUBSCRIBE)); } }
/** * Notify all plugin callbacks of the specified action. * * @param action Action to perform. * @param data Event-dependent data (may be null). * @param async If true, callbacks are done asynchronously. */ private void executeAction(PluginAction action, boolean async, Object data) { if (hasListeners() || action == PluginAction.LOAD) { PluginEvent event = new PluginEvent(this, action, data); if (async) { EventUtil.post(event); } else { onAction(event); } } }