# BaseEvent

`com.jsmacrosce.jsmacros.core.event.BaseEvent`

Base class for event payloads dispatched to registered listeners. By default, the runtime
class's [Event](Event.md) 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](../../../../../../events/com/jsmacrosce/jsmacros/core/event/impl/EventCustom.md) does.  

Dispatch waits for cancellable events, or for listeners requesting a join when joining is
permitted. Otherwise listener work may continue after [trigger()](#com.jsmacrosce.jsmacros.core.event.BaseEvent_trigger-) returns, so changes to the
event may be too late for the code that raised it. See [IEventListener.joined()](IEventListener.md#com.jsmacrosce.jsmacros.core.event.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 {#com.jsmacrosce.jsmacros.core.event.BaseEvent_constructor-Core-}

```js
new BaseEvent(Core<?, ?> runner)
```

Sets the core through which this event is dispatched.

**Parameters:**
- `runner`: the core this event is dispatched through

## Fields

### runner {#com.jsmacrosce.jsmacros.core.event.BaseEvent_runner}

```js
runner: Core<?, ?>
```

The core through which this event is dispatched.

## Methods

### cancel {#com.jsmacrosce.jsmacros.core.event.BaseEvent_cancel-}

```js
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](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/UnsupportedOperationException.html) if this event is not cancellable.

### cancellable {#com.jsmacrosce.jsmacros.core.event.BaseEvent_cancellable-}

```js
cancellable(): boolean
```

whether this event can be cancelled, read from [Event.cancellable()](Event.md#com.jsmacrosce.jsmacros.core.event.Event_cancellable-) on the subclass.  
It is the flag [cancel()](#com.jsmacrosce.jsmacros.core.event.BaseEvent_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 {#com.jsmacrosce.jsmacros.core.event.BaseEvent_getEventName-}

```js
getEventName(): String
```

The event name from [Event.value()](Event.md#com.jsmacrosce.jsmacros.core.event.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 {#com.jsmacrosce.jsmacros.core.event.BaseEvent_isCanceled-}

```js
isCanceled(): boolean
```

Whether [cancel()](#com.jsmacrosce.jsmacros.core.event.BaseEvent_cancel-) has been called on this event.

**Returns:** `true` once something has called [cancel()](#com.jsmacrosce.jsmacros.core.event.BaseEvent_cancel-) on this instance.

### joinable {#com.jsmacrosce.jsmacros.core.event.BaseEvent_joinable-}

```js
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](BaseEventRegistry.md#com.jsmacrosce.jsmacros.core.event.BaseEventRegistry_joinableEvents).

**Returns:** `true` if the event is cancellable or declares itself joinable.

### trigger {#com.jsmacrosce.jsmacros.core.event.BaseEvent_trigger-}

```js
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.
