Skip to content

BaseEvent ​

com.jsmacrosce.jsmacros.core.event.BaseEvent

Base class for event payloads dispatched to registered listeners. By default, the runtime class's Event annotation supplies its name and cancellable/joinable flags; without an annotation, the simple class name is used and both flags are false. Subclasses may override these methods, as EventCustom does.

Dispatch waits for cancellable events, or for listeners requesting a join when joining is permitted. Otherwise listener work may continue after trigger() returns, so changes to the event may be too late for the code that raised it. See IEventListener.joined() for the listener-side contract.

js
const listener = JsMacros.on("SendMessage", JavaWrapper.methodToJava(event => {
 if (event.message === "/hello") {
   // Cancel before the message is sent or added to chat history.  
   event.cancel();  
 }
 // Remove a one-shot listener using the handle returned by on().  
 JsMacros.off(listener);  
}));

Constructors ​

new BaseEvent ​

new BaseEvent(Core<?, ?> runner)#
Sets the core through which this event is dispatched.

Parameters:

  • runner: the core this event is dispatched through

Fields ​

runner ​

runner: Core<?, ?>read-only#
The core through which this event is dispatched.

Methods ​

cancel ​

cancel(): void#
Marks this event cancelled. Dispatch waits for cancellable events; cancel before releasing the event lock for the raising code to observe the flag when dispatch returns. Throws UnsupportedOperationException if this event is not cancellable.

cancellable ​

cancellable(): boolean#
whether this event can be cancelled, read from Event.cancellable() on the subclass. It is the flag cancel() checks, so it is also what decides whether a cancel throws rather than sticking. A subclass with no @Event defaults to false.
Returns: true if the event declares itself cancellable.

getEventName ​

getEventName(): String#
The event name from Event.value(), or the runtime class's simple name if it has no annotation.
Returns: the name from the annotation, for example SendMessage, or the runtime class's simple name when no annotation is present.

isCanceled ​

isCanceled(): boolean#
Whether cancel() has been called on this event.
Returns: true once something has called cancel() on this instance.

joinable ​

joinable(): boolean#
Whether this event permits joining based on its own cancellable or joinable flag. Named-event dispatch may also permit joining based on BaseEventRegistry.joinableEvents.
Returns: true if the event is cancellable or declares itself joinable.

trigger ​

trigger(): void#
Dispatches this event through its core's profile. Listener work may outlive this call unless dispatch joins it; custom events dispatch under their custom name.