-
Notifications
You must be signed in to change notification settings - Fork 34
Using Custom Event Handlers
ced777ric edited this page Mar 5, 2025
·
4 revisions
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 : CustomEventsHandlerAnd 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
}
}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);
}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);
}- Making Plugins
- Features
- Guides