Added enablePlugin() and disablePlugin() (#13)

* Exposed loaded plugins in FourKitHost with public getLoadedPlugins()

* Fixed bad reference to ServerPlugins

* Forgot that the PluginLoader was nullable, handled it

* Implemented getPlugin(name) and getPlugins() in FourKit.cs

* Implemented enablePlugin(plugin) and disablePlugin(plugin) in FourKit.cs

---------

Co-authored-by: UniPM <zoc6x8voc@mozmail.com>
This commit is contained in:
UniPM 2026-04-06 02:06:10 -05:00 committed by GitHub
parent 18a673bd46
commit 94bed94d00
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 54 additions and 31 deletions

View file

@ -119,41 +119,52 @@ internal sealed class PluginLoader
{
foreach (var plugin in _plugins)
{
try
{
InvokePluginMethod(plugin, "onEnable", "OnEnable");
string pName = GetPluginString(plugin, "name", "getName", "GetName", plugin.GetType().Name);
ServerLog.Info("fourkit", $"Enabled: {pName}");
FourKit.FireEvent(new PluginEnableEvent(plugin));
}
catch (Exception ex)
{
string pName = GetPluginString(plugin, "name", "getName", "GetName", plugin.GetType().Name);
ServerLog.Error("fourkit", $"Error enabling {pName}: {ex.Message}");
}
EnablePlugin(plugin);
}
}
public void DisableAll()
{
for (int i = _plugins.Count - 1; i >= 0; i--)
foreach (var plugin in _plugins)
{
try
{
InvokePluginMethod(_plugins[i], "onDisable", "OnDisable");
string pName = GetPluginString(_plugins[i], "name", "getName", "GetName", _plugins[i].GetType().Name);
ServerLog.Info("fourkit", $"Disabled: {pName}");
FourKit.FireEvent(new PluginDisableEvent(_plugins[i]));
}
catch (Exception ex)
{
string pName = GetPluginString(_plugins[i], "name", "getName", "GetName", _plugins[i].GetType().Name);
ServerLog.Error("fourkit", $"Error disabling {pName}: {ex.Message}");
}
DisablePlugin(plugin);
}
}
public void EnablePlugin(ServerPlugin plugin)
{
try
{
InvokePluginMethod(plugin, "onEnable", "OnEnable");
string pName = GetPluginString(plugin, "name", "getName", "GetName", plugin.GetType().Name);
ServerLog.Info("fourkit", $"Enabled: {pName}");
FourKit.FireEvent(new PluginEnableEvent(plugin));
}
catch (Exception ex)
{
string pName = GetPluginString(plugin, "name", "getName", "GetName", plugin.GetType().Name);
ServerLog.Error("fourkit", $"Error enabling {pName}: {ex.Message}");
}
}
public void DisablePlugin(ServerPlugin plugin)
{
try
{
InvokePluginMethod(plugin, "onDisable", "OnDisable");
string pName = GetPluginString(plugin, "name", "getName", "GetName", plugin.GetType().Name);
ServerLog.Info("fourkit", $"Disabled: {pName}");
FourKit.FireEvent(new PluginDisableEvent(plugin));
}
catch (Exception ex)
{
string pName = GetPluginString(plugin, "name", "getName", "GetName", plugin.GetType().Name);
ServerLog.Error("fourkit", $"Error disabling {pName}: {ex.Message}");
}
}
private static void InvokePluginMethod(ServerPlugin plugin, string camelName, string pascalName)
{
Type type = plugin.GetType();