Package xyz.janboerman.scalaloader.event
Class EventBus
java.lang.Object
xyz.janboerman.scalaloader.event.EventBus
An event bus for ScalaPlugin
Events.
The instance of this event bus can be obtained in your ScalaPlugin's main class using super.getEventBus() or IScalaLoader.getEventBus().- See Also:
- API Note:
- JavaPlugins should not use this class, they are better off using Bukkit's PluginManager api.
- Implementation Note:
- Some of the internals of this class rely on the fact that the bytecode of ScalaPlugins is transformed using
EventTransformations.transform(byte[], ClassLoader)before they are "defined" by the classloader.
-
Constructor Summary
ConstructorsConstructorDescriptionEventBus(PluginManager pluginManager) Deprecated.not meant to be constructed explicitly. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCalls the event, allowing listeners to take actions based on the event.booleanCalls the event so, allowing listeners to take action based on the event.voidregisterEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin) Register an event executor that is executed when an event is called.voidregisterEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) Register an event executor that is executed when an event is called.registerEvent(Class<E> event, L listener, EventPriority priority, EventExecutor<L, E> executor, Plugin plugin) Register an event executor that is executed when an event is called.registerEvent(Class<E> event, L listener, EventPriority priority, EventExecutor<L, E> executor, Plugin plugin, boolean ignoreCancelled) Register an event executor that is executed when an event is called.voidregisterEvents(Listener listener, Plugin plugin) Register a listener.
-
Constructor Details
-
EventBus
Deprecated.not meant to be constructed explicitly. UseIScalaPlugin.getEventBus()orIScalaLoader.getEventBus().Construct the event bus.- Parameters:
pluginManager- the server's PluginManager
-
-
Method Details
-
callEvent
Calls the event so, allowing listeners to take action based on the event. Returns whether the event is allowed to execute.- Parameters:
event- the event- Returns:
- true if the event is allowed to happen, otherwise false
- API Note:
- if the event does not implement
Cancellable, true is always returned.
-
callEvent
Calls the event, allowing listeners to take actions based on the event. Returns whether the event is allowed to execute.- Parameters:
event- the event- Returns:
- true if the event is allowed to happen, otherwise false
- Throws:
RuntimeException- if the type of the passed argument is not a subtype ofEventorEvent.- API Note:
- this method is not type-safe. The argument's type must be a subtype of either
EventorEvent., if the event does not implementCancellableorCancellable, true is always returned.
-
registerEvents
Register a listener. The EventBus will try to createEventExecutors based on methods in the listener's class that are annotated withEventHandler. These methods must have a single parameter, that is of a subtype ofEventorEvent.- Parameters:
listener- the event listenerplugin- the plugin for which the EventExecutors are created
-
registerEvent
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) Register an event executor that is executed when an event is called.- Parameters:
event- the eventlistener- the event listenerpriority- the priority of the executorexecutor- the event executorplugin- the PluginignoreCancelled- whether to ignore cancelled events (false == don't ignore == handle cancelled events too)
-
registerEvent
public <L extends Listener,E extends Event> void registerEvent(Class<E> event, L listener, EventPriority priority, EventExecutor<L, E> executor, Plugin plugin, boolean ignoreCancelled) Register an event executor that is executed when an event is called.- Type Parameters:
L- the listener typeE- the event type- Parameters:
event- the eventlistener- the event listenerpriority- the priority of the executorexecutor- the event executorplugin- the PluginignoreCancelled- whether to ignore cancelled events (false == don't ignore == handle cancelled events too)- Implementation Note:
- can only be called from within ScalaPlugins!
-
registerEvent
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin) Register an event executor that is executed when an event is called.- Parameters:
event- the eventlistener- the event listenerpriority- the priority of the executorexecutor- the event executorplugin- the plugin
-
registerEvent
public <L extends Listener,E extends Event> void registerEvent(Class<E> event, L listener, EventPriority priority, EventExecutor<L, E> executor, Plugin plugin) Register an event executor that is executed when an event is called.- Type Parameters:
L- the listener typeE- the event type- Parameters:
event- the eventlistener- the event listenerpriority- the priority of the executorexecutor- the event executorplugin- the Plugin- Implementation Note:
- can only be called from within ScalaPlugins!
-