Class MatchboxEvent

java.lang.Object
com.ohacd.matchbox.api.MatchboxEvent
Direct Known Subclasses:
AbilityUseEvent, CureEvent, GameEndEvent, GameStartEvent, PhaseChangeEvent, PlayerEliminateEvent, PlayerJoinEvent, PlayerLeaveEvent, PlayerVoteEvent, SwipeEvent

public abstract class MatchboxEvent extends Object
Base class for all Matchbox events.

All events extend this class and implement dispatch(MatchboxEventListener) method to call the appropriate method on the listener.

This follows the visitor pattern for type-safe event handling.

Since:
0.9.5
  • Constructor Details

    • MatchboxEvent

      protected MatchboxEvent()
      Creates a new MatchboxEvent with the current timestamp.
    • MatchboxEvent

      protected MatchboxEvent(long timestamp)
      Creates a new MatchboxEvent with a specific timestamp.
      Parameters:
      timestamp - the event timestamp in milliseconds
  • Method Details

    • dispatch

      public abstract void dispatch(@NotNull @NotNull MatchboxEventListener listener)
      Dispatches this event to the appropriate listener method.

      This method uses the visitor pattern to call the correct handler method based on the concrete event type. Implementing classes should call super.dispatch(listener) as the first line.

      Parameters:
      listener - the listener to dispatch to
      Throws:
      IllegalArgumentException - if listener is null
    • getTimestamp

      public long getTimestamp()
      Gets the timestamp when this event was created.
      Returns:
      event timestamp in milliseconds since epoch
    • toString

      public String toString()
      Overrides:
      toString in class Object