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 a listener only when that listener requests joined handling and the event permits joining. A joined listener may cancel or change the event while its event lock is held.
A listener that did not request joined handling receives a read-only delivery: dispatch does not wait for it, so the game may already have read the event by the time its callback runs. It cannot cancel or change the event. Call canModify() to check the current delivery before attempting a change.

js
const listener = JsMacros.on("SendMessage", true, JavaWrapper.methodToJava(event => {
  if (event.getMessage() === "/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. This is only valid from a joined listener while its event lock is still held; see canModify(). Cancel before releasing the lock so the raising code observes the flag when dispatch returns. Throws UnsupportedOperationException if this event is not cancellable, and IllegalStateException if the current delivery cannot change the event.

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.

canModify ​

canModify(): booleanSince2.2.0#
Whether the current callback may cancel or change this event. This is true for a joined listener while its event lock is still held, for the raising thread during dispatch, and for a custom event's creator between dispatches. It is false for a non-joined listener, after the event lock is released, and for built-in events after dispatch returns.
Returns: true if the current delivery may cancel or change the event

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.