Class EventBus

java.lang.Object
xyz.janboerman.scalaloader.event.EventBus

public class EventBus extends Object
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 Details

  • Method Details

    • callEvent

      public boolean callEvent(Event event)
      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

      public boolean callEvent(Object event)
      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 of Event or Event.
      API Note:
      this method is not type-safe. The argument's type must be a subtype of either Event or Event., if the event does not implement Cancellable or Cancellable, true is always returned.
    • registerEvents

      public void registerEvents(Listener listener, Plugin plugin)
      Register a listener. The EventBus will try to create EventExecutors based on methods in the listener's class that are annotated with EventHandler. These methods must have a single parameter, that is of a subtype of Event or Event.
      Parameters:
      listener - the event listener
      plugin - 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 event
      listener - the event listener
      priority - the priority of the executor
      executor - the event executor
      plugin - the Plugin
      ignoreCancelled - 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 type
      E - the event type
      Parameters:
      event - the event
      listener - the event listener
      priority - the priority of the executor
      executor - the event executor
      plugin - the Plugin
      ignoreCancelled - 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 event
      listener - the event listener
      priority - the priority of the executor
      executor - the event executor
      plugin - 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 type
      E - the event type
      Parameters:
      event - the event
      listener - the event listener
      priority - the priority of the executor
      executor - the event executor
      plugin - the Plugin
      Implementation Note:
      can only be called from within ScalaPlugins!