EventRegistry
Namespace Mc.Scripting · Kind class (sealed)
public sealed class EventRegistryEvent subscription and firing, scoped to a plugin (everything is released on unload).
Examples
Section titled “Examples”Priorities, cancellation and mutation
// Block spam (High runs after Normal, so other plugins' edits are already applied)Events.On((ref PlayerChatEvent e) =>{ if (e.Message.Contains("spam", StringComparison.OrdinalIgnoreCase)) e.Cancelled = true;}, EventPriority.High);
// Rewrite a mutable fieldEvents.On((ref EntityDamageEvent e) => e.Amount *= 0.5f);
// Observe the final outcome without changing itEvents.On((ref PlayerChatEvent e) => Log.Info(e.Cancelled ? "chat was blocked" : "chat delivered"), EventPriority.Monitor, receiveCancelled: true);Methods
Section titled “Methods”| Member | Description |
|---|---|
bool Fire<T>(ref T ev) where T : struct, IEvent |
Fires an event through the native bus (native and managed handlers, by priority). |
bool HasSubscribers<T>() where T : struct, IEvent |
Whether anybody (native or managed) listens to T. |
On<T> |
Subscribes listener to events of type T. |
Fire<T>
Section titled “Fire<T>”public bool Fire<T>(ref T ev) where T : struct, IEventFires an event through the native bus (native and managed handlers, by priority). Returns false if it was cancelled.
Parameters
| Name | Type | Description |
|---|---|---|
ev |
ref T |
Returns bool
HasSubscribers<T>
Section titled “HasSubscribers<T>”public bool HasSubscribers<T>() where T : struct, IEventWhether anybody (native or managed) listens to T.
Returns bool
public Subscription On<T>(EventListener<T> listener, EventPriority priority = EventPriority.Normal, bool receiveCancelled = false) where T : struct, IEventSubscribes listener to events of type T.
Parameters
| Name | Type | Description |
|---|---|---|
listener |
EventListener<T> |
Handler, invoked on the tick thread with the event by reference. |
priority |
EventPriority = EventPriority.Normal |
Lower runs first; native and managed handlers share one ordering. |
receiveCancelled |
bool = false |
Also invoke the listener after a higher-priority handler cancelled the event. |
Returns Subscription