Class EventHandler<T extends Event>

java.lang.Object
net.lucypoulton.squirtgun.platform.event.EventHandler<T>
Type Parameters:
T - the event to handle
All Implemented Interfaces:
Comparable<EventHandler<?>>

public class EventHandler<T extends Event> extends Object implements Comparable<EventHandler<?>>
An event handler.
  • Method Details

    • eventType

      public Class<T> eventType()
      The type of event that this handler accepts.
    • priority

      public EventPriority priority()
      This handler's priority.
    • executesOnCancel

      public boolean executesOnCancel()
      Whether this handler should be called if a handler with a higher priority has cancelled the event. This value is not used with events that aren't cancellable.
    • execute

      public void execute(T event)
      Executes the handler.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(@NotNull @NotNull EventHandler<?> o)
      Specified by:
      compareTo in interface Comparable<T extends Event>
    • builder

      public static <T extends Event> EventHandler.Builder<T> builder(Class<T> eventType)
      Creates a new builder.
      Type Parameters:
      T - the type of event to listen for
      Returns:
      a new builder
    • executes

      public static <T extends Event> EventHandler<T> executes(Class<T> event, Consumer<T> handler)
      Creates a new builder from a consumer, with event priority EventPriority.NORMAL.
      Type Parameters:
      T - the event to handle
      Parameters:
      handler - the handler to execute