Class Event

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

public abstract class Event extends Object

An alternative to Event for ScalaPlugins. This class aims to reduce boilerplate for ScalaPlugin events, allowing you to omit the public HandlerList getHandlers() and public static HanderList getHandlerList() from your event definition. At runtime subclasses of this event will be transformed by the class classloader to extend Event instead and the HanderList-related methods will be generated. If a static HandlerList field is absent, then that will be generated too.

Listening to events can still be done using Bukkit's EventHandler/Listener api, for example:


  import org.bukkit.event.{EventHandler, EventPriority}
  import xyz.janboerman.scalaloader.event.{Event, Cancellable}
  import xyz.janboerman.scalaloader.plugin.{ScalaPlugin, ScalaPluginDescription}
  import xyz.janboerman.scalaloader.plugin.description.{Scala, ScalaVersion, Api, ApiVersion}

  case class HomeTeleportEvent(player: Player, home: Location) extends Event with Cancellable

  object HomeTeleportListener extends Listener {
      @EventHandler(priority = EventPriority.MONITOR)
      def onHomeTeleport(event: HomeTeleportEvent): Unit = {
          event.player.sendMessage("Welcome home!")
      }
  }

  @Scala(version = ScalaVersion.v2_13_5)
  @Api(ApiVersion.v1_16)
  object MyPlugin extends ScalaPlugin(new ScalaPluginDescription("MyPlugin", "1.0")) {
      override def onEnable(): Unit = {
          getServer.getPluginManager.registerEvents(HomeTeleportListener, this)
      }
  }
 

Alternatively, it's also possible to register your event Listener using a lambda, there's a EventExecutor too for ScalaLoader Events.

See Also:
Implementation Note:
Because transformations are done at the classloader-level, JavaPlugins cannot extend this class because they use a different classloader implementation. JavaPlugins can listen to instances of subclasses of Events just fine through Bukkit's EventHandler reflection api. It is only the Event base type that is toxic, don't ever use it explicitly in a JavaPlugin.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct an event that is executed in the server thread.
    Event(boolean asynchronous)
    Constructor that allows you to specify whether this event is called and executed asynchronously.
  • Method Summary

    Modifier and Type
    Method
    Description
    Get the event's name.
    boolean
    Tests whether the event is performed asynchronously - meaning it is executed outside of the server's primary thread.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Event

      public Event(boolean asynchronous)
      Constructor that allows you to specify whether this event is called and executed asynchronously.
      Parameters:
      asynchronous - true if the event is asynchronous, false if the event is executed in the server thread.
      Implementation Note:
      can only be used by ScalaPlugins!
    • Event

      public Event()
      Construct an event that is executed in the server thread.
      Implementation Note:
      can only be used by ScalaPlugins!
  • Method Details

    • isAsynchronous

      public boolean isAsynchronous()
      Tests whether the event is performed asynchronously - meaning it is executed outside of the server's primary thread.
      Returns:
      true if the event is asynchronous, otherwise false
      See Also:
    • getEventName

      public String getEventName()
      Get the event's name. The default implementation returns the name of the class of the event.
      Returns:
      the name of the event