Class EventManager

java.lang.Object
live.crowdcontrol.cc4j.util.EventManager

public final class EventManager extends Object
Manages the dispatching and invoking of events.
  • Field Details

  • Constructor Details

    • EventManager

      public EventManager(@NotNull @NotNull CrowdControl parent)
      Create an EventManager.
      Parameters:
      parent - Crowd Control instance
  • Method Details

    • dispatch

      public <T> void dispatch(@NotNull @NotNull CCEventType<T> event, @NotNull T body)
      Dispatches an event to its listeners and stores it in a temporary log.
      Parameters:
      event - event type
      body - body to pass onto listeners
    • dispatch

      public void dispatch(@NotNull @NotNull CCEventType<Void> event)
      Dispatches a Void event to its listeners and stores it in a temporary log.
      Parameters:
      event - event type
    • registerEventConsumer

      public <T> void registerEventConsumer(@NotNull @NotNull CCEventType<T> event, @NotNull @NotNull Consumer<T> listener, int catchUpPeriod)
      Registers a listener to be called as appropriate.

      catchUpPeriod determines the time in seconds in which to look for recently sent events to catch the listener up on events it just missed. Set to 0 to disable, or -1 to fetch all records (within the 100 most recent).

      Parameters:
      event - the type of event to register for
      listener - the function to call as necessary
      catchUpPeriod - duration in seconds or -1
    • registerEventConsumer

      public <T> void registerEventConsumer(@NotNull @NotNull CCEventType<T> event, @NotNull @NotNull Consumer<T> listener)
      Registers a listener to be called as appropriate.

      If this event has recently been dispatched, then your listener will immediately be invoked. See registerEventConsumer(CCEventType, Consumer, int) for more information on the catch-up period.

      Parameters:
      event - the type of event to register for
      listener - the function to call as necessary
    • registerEventRunnable

      public void registerEventRunnable(@NotNull @NotNull CCEventType<?> event, @NotNull @NotNull Runnable listener, int catchUpPeriod)
      Registers a listener to be called as appropriate.

      catchUpPeriod determines the time in seconds in which to look for recently sent events to catch the listener up on events it just missed. Set to 0 to disable, or -1 to fetch all records (within the 100 most recent).

      Parameters:
      event - the type of event to register for
      listener - the function to call as necessary
      catchUpPeriod - duration in seconds or -1
    • registerEventRunnable

      public void registerEventRunnable(@NotNull @NotNull CCEventType<?> event, @NotNull @NotNull Runnable listener)
      Registers a listener to be called as appropriate.

      If this event has recently been dispatched, then your listener will immediately be invoked. See registerEventRunnable(CCEventType, Runnable, int) for more information on the catch-up period.

      Parameters:
      event - the type of event to register for
      listener - the function to call as necessary