Class EventHandler<E extends Event>

java.lang.Object
org.polyfrost.oneconfig.api.event.v1.invoke.EventHandler<E>
Type Parameters:
E - The event type
All Implemented Interfaces:
Comparable<EventHandler<E>>

public abstract class EventHandler<E extends Event> extends Object implements Comparable<EventHandler<E>>
Class which represents an event handler.
See Also:
  • Field Details

  • Constructor Details

    • EventHandler

      public EventHandler()
  • Method Details

    • ofRemoving

      public static <E extends Event> EventHandler<E> ofRemoving(Class<E> cls, Predicate<? super E> handler)
      Create an event handler from a consumer, in a fabric-style way.
      Type Parameters:
      E - the event type
      Parameters:
      cls - the event class
      handler - the predicate for the event. Return true to remove the event handler.
      Returns:
      the event handler
    • of

      public static <E extends Event> EventHandler<E> of(Class<E> cls, Consumer<? super E> handler)
      Create an event handler from a consumer, in a fabric-style way.
      Type Parameters:
      E - the event type
      Parameters:
      cls - the event class
      handler - the consumer
      Returns:
      the event handler
    • of

      public static <E extends Event> EventHandler<E> of(Class<E> cls, Runnable handler)
    • handle

      public abstract boolean handle(E event)
    • getEventClass

      public abstract Class<E> getEventClass()
    • getPriority

      public int getPriority()
      Set the priority of this event handler. Higher priority handlers are called first.
      The default priority is 0.
      if two handlers have the same priority, the order of registration is used.
    • compareTo

      public final int compareTo(@NotNull @NotNull EventHandler<E> o)
      Specified by:
      compareTo in interface Comparable<E extends Event>
    • register

      public final EventHandler<E> register()
      Convenience method for registering this event handler. Equivalent to EventManager.INSTANCE.register(this).
      Returns:
      this
    • unregister

      public final EventHandler<E> unregister()
    • onError

      @Internal public final boolean onError()
    • equals

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

      public boolean equals(EventHandler<?> other)
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object