mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-05-13 04:33:52 +00:00
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:
parent
18a673bd46
commit
94bed94d00
3 changed files with 54 additions and 31 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue