Skip to content

Using Custom Event Handlers

ced777ric edited this page Mar 5, 2025 · 4 revisions

Creating your Custom Event Handlers

For this example, we will create an empty class called MyCustomEventHandlers.cs.

All your custom event handlers class has to do is to inherit CustomEventsHandler.

public class MyCustomEventHandlers : CustomEventsHandler

And voilà, you can start using any event inside LabAPI by just overriding its target method.

public class MyCustomEventHandlers : CustomEventsHandler
{
    public override void OnRoundEnded(RoundEndedEventArgs args)
    {
        // Implement your custom logic here
    }
}

Registering the event handlers

All your event subscriptions should be done when your plugin is being enabled.

Instead of subscribing each method, you can pass your handler to RegisterEventsHandler inside CustomHandlersManager

public MyCustomEventHandlers Events { get; } = new ();

public override void Enable()
{
    CustomHandlersManager.RegisterEventsHandler(Events);
}

Unregistering the event handlers

At the same time, all your event unsubscriptions should be done when your plugin is being disabled.

You can use againCustomHandlersManager, ⁣ but this time calling UnregisterEventsHandler.

public override void Disable()
{
    CustomHandlersManager.UnregisterEventsHandler(Events);
}

Clone this wiki locally