Annotation Interface Subscribe


@Retention(RUNTIME) @Target(METHOD) public @interface Subscribe
Marks a method as an event handler.

The method must have exactly one parameter, which is the event type to handle. The method can be public, protected, or package-private.

public class MyListener {
    @Subscribe
    public void onPlayerConnect(PlayerConnectEvent event) {
        // Handle event
    }

    @Subscribe(priority = EventPriority.EARLY)
    public void onPacket(PacketEvent event) {
        // Handle packet early
    }
}
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Whether this handler should receive cancelled events.
    The priority of this event handler.
  • Element Details

    • priority

      EventPriority priority
      The priority of this event handler. Handlers with lower priority values are called first.
      Returns:
      the handler priority
      Default:
      NORMAL
    • ignoreCancelled

      boolean ignoreCancelled
      Whether this handler should receive cancelled events.
      Returns:
      true to receive cancelled events
      Default:
      false