Interface CarbonEventHandler


The CarbonEventHandler is responsible for managing event subscriptions and emitting events.
Since:
3.0.0
  • Method Details

    • subscribe

      <T extends CarbonEvent> CarbonEventSubscription<T> subscribe(Class<T> eventClass, CarbonEventSubscriber<T> subscriber)
      Registers a subscriber for the given event class.
      Type Parameters:
      T - the class to listen for
      Parameters:
      eventClass - the class to listen for
      subscriber - the subscriber that's executed when the event is emitted
      Returns:
      the subscription, so that it may be unregistered
      Since:
      2.0.0
    • subscribe

      <T extends CarbonEvent> CarbonEventSubscription<T> subscribe(Class<T> eventClass, int order, boolean acceptsCancelled, CarbonEventSubscriber<T> subscriber)
      Registers a subscriber for the given event class.
      Includes extra values to control when the consumer is executed.
      Type Parameters:
      T - the class to listen for
      Parameters:
      eventClass - the class to listen for
      order - the order of the consumer
      acceptsCancelled - if the consumer should be executed if the event is cancelled early
      subscriber - the consumer that's executed when the event is emitted
      Returns:
      the subscription, so that it may be unregistered
      Since:
      2.0.0
    • emit

      <T extends CarbonEvent> void emit(T event)
      Emits the supplied event.

      Events are modified in place, meaning you must keep a reference to the event yourself if you wish to inspect it's state after this call.

      Type Parameters:
      T - the class to emit
      Parameters:
      event - the event to be emitted
      Since:
      2.0.0