Skip to content

EventRegistry

Namespace Mc.Scripting · Kind class (sealed)

public sealed class EventRegistry

Event subscription and firing, scoped to a plugin (everything is released on unload).

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 field
Events.On((ref EntityDamageEvent e) => e.Amount *= 0.5f);
// Observe the final outcome without changing it
Events.On((ref PlayerChatEvent e) => Log.Info(e.Cancelled ? "chat was blocked" : "chat delivered"),
EventPriority.Monitor, receiveCancelled: true);
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.
public bool Fire<T>(ref T ev) where T : struct, IEvent

Fires 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

public bool HasSubscribers<T>() where T : struct, IEvent

Whether 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, IEvent

Subscribes 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

EventPriority · IEvent · Subscription