Interface ListenerHandle<E extends Event>

Type Parameters:
E - the event type

@Experimental public sealed interface ListenerHandle<E extends Event>
Represents a key to a listenable event, retrievable from EventNode.getHandle(Class). Useful to avoid map lookups.

It is recommended to store instances of this class in static final fields.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    call(E event)
    Calls the given event.
    boolean
    Gets if any listener has been registered for the given handle.
  • Method Details

    • call

      void call(@NotNull E event)
      Calls the given event. Will try to fast exit the execution when possible if hasListener() return false.

      Anonymous and subclasses are not supported, events must have the exact type E.

      Parameters:
      event - the event to call
    • hasListener

      boolean hasListener()
      Gets if any listener has been registered for the given handle. May trigger an update if the cached data is not correct.

      Useful if you are able to avoid expensive computation in the case where the event is unused. Be aware that call(Event) has similar optimization built-in.

      Returns:
      true if the event has 1 or more listeners