#CustomEventHandler Plugin, events automatically registering for you!

1 messages · Page 1 of 1 (latest)

safe widget
#

A powerful and easy-to-use event management framework for SCP: Secret Laboratory plugins using LabAPI. CustomEventHandler automatically discovers, registers, and manages your event handlers, eliminating boilerplate code and streamlining plugin development.

🌟 Features

  • Automatic Event Discovery: Automatically finds and registers all event classes in a specified namespace
  • Simple Integration: Just implement IEventType and your events are ready to go
  • Clean Code: Reduces boilerplate with automatic registration/unregistration
  • Type-Safe: Uses reflection to ensure only valid event handlers are registered
  • High Performance: Minimal overhead with efficient event management
  • Easy Debugging: Built-in debug configuration for development

📋 Requirements

  • SCP: Secret Laboratory Dedicated Server
  • LabAPI 1.1.4 or higher
  • .NET Framework 4.8

📦 Installation

For Plugin Developers (Using CustomEventHandler in your plugin)

  1. Download the latest CustomEventHandler.dll from the Releases page
  2. Place it in your server's %AppData%\Roaming\SCP Secret Laboratory\LabAPI\dependencies\global folder
  3. Add a reference to CustomEventHandler.dll in your plugin project
  4. Start using the event management features!

For Server Owners

  1. Download the latest CustomEventHandler.dll from the Releases page
  2. Place it in your server's .config\SCP Secret Laboratory\LabAPI\dependencies\global folder
  3. Restart your server
#

🚀 Quick Start

Creating an Event Handler

Create a class that implements IEventType with Register() and Unregister() methods:

namespace TemplateTest.Events;

using CustomEventHandler.Events;
using LabApi.Events.Arguments.PlayerEvents;
using LabApi.Events.Handlers;

public class PlayerJoinedEvent : IEventType
{
    // Subscribe to the event
    public void Register() =>
        PlayerEvents.Joined += OnPlayerJoined;

    // Unsubscribe from the event
    public void Unregister() =>
        PlayerEvents.Joined -= OnPlayerJoined;

    private void OnPlayerJoined(PlayerJoinedEventArgs ev)
    {
        // Your event logic here
        Log.Info($"{ev.Player.Nickname} joined the server!");
    }
}
#

Using in Your Plugin

In your main plugin class:

using System;
using LabApi.Features;
using LabApi.Features.Console;
using LabApi.Loader.Features.Plugins.Enums;
using CustomEventHandler.Events;

namespace YourPlugin;

public class MyPlugin : Plugin<Config>
{
    public static Plugin Instance { get; private set; } = null!;
    public override string Name => "YourPlugin";
    public override string Author => "YourName";
    public override string Description => "A SCP:SL LabAPI plugin";
    public override Version Version => new(1, 0, 0);
    public override Version RequiredApiVersion => new(LabApiProperties.CompiledVersion);
    public override LoadPriority Priority => LoadPriority.High;
    private IEventList Events => EventsContainer.GetEvents("YourPlugin.Events");

    public override void Enable()
    {
        if (Config is null)
            throw new Exception("Config is null!");
        
        if (Config.Debug)
            Logger.Debug("Debug mode enabled.");
            
        Instance = this;
        
        // Automatically discover and register all events in your Events namespace
        Events.RegisterEvents();
    }

    public override void Disable()
    {
        // Unregister all events when plugin is disabled
        Events.UnregisterEvents();
        
        Log.Info("Plugin disabled and events unregistered!");
        Instance = null!;
    }
}
#

CustomEventHandler Plugin, events automatically registering for you!

sudden fern
#

Excuse me, you just kinda reinvented CustomEventsHandler from labapi itself..

safe widget
sudden fern
#

Yes but.. whats the point of this?

#

This feature exists in labapi and uses method overrides for events..

safe widget
#

Well I'm kinda new to labapi so due to the lack of documentation I didn't know what was the best approach for subscribing to events

#

I only knew about EventsHandler but whenever we made a new event file, we had to add it in the EventsHandler

#

I thought it would be better to have a folder with every event, and the Plugin file looking through it to register every single event without having to add any line of code inside of it

final mason
#

We're aware that the documentation isn't very extensive, but it covers most basic steps

safe widget
#

I see I see

#

Welp, atleast I did some practice ig

sudden fern
#

Sure, feel free to keep it here

safe widget
#

What's the ConnectionProvider used for btw @final mason ?

final mason
#

I have no clue what that is

safe widget
#

lol

sudden fern
#

That was placeholder text for when the wiki was first created tbh

safe widget
#

Oh alr, I thought it was a thing

sudden fern
#

We do plan on expanding it, of course.

final mason
#

Yeah this is kinda a horrible example xd

safe widget
#

it would be interesting to put CustomEventsHandler as an example

sudden fern
safe widget
#

i mean to replace the ConnectionProvider in the main plugin

noble dagger
#

Idea for you

#

One thing I did in my plugin was scan my assembly using reflection to automatically instantiate all my plugins
If you're willing to get super in the weeds regarding C# and plugin development, you could make a plugin that uses source generation to automatically instantiate CustomEventHandlers that haven't already been instantiated
Personally, it's a small development feature I get a lot of use out of
Being able to make a new class, make it derive from CustomEventHandler, and have it work automatically is really awesome

final mason
#

source-generators 🗣️🗣️

safe widget
#

I'll look into that

#

Rn I'm scanning the CallingAssembly

#

I guess you're talking about another one

noble dagger
#

Using source generation