Package com.ohacd.matchbox.api
Class MatchboxEvent
java.lang.Object
com.ohacd.matchbox.api.MatchboxEvent
- Direct Known Subclasses:
AbilityUseEvent,CureEvent,GameEndEvent,GameStartEvent,PhaseChangeEvent,PlayerEliminateEvent,PlayerJoinEvent,PlayerLeaveEvent,PlayerVoteEvent,SwipeEvent
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 Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new MatchboxEvent with the current timestamp.protectedMatchboxEvent(long timestamp) Creates a new MatchboxEvent with a specific timestamp. -
Method Summary
Modifier and TypeMethodDescriptionabstract voiddispatch(@NotNull MatchboxEventListener listener) Dispatches this event to the appropriate listener method.longGets the timestamp when this event was created.toString()
-
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
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
-