Exposing ServerPlugins (#11)

* 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

---------

Co-authored-by: UniPM <zoc6x8voc@mozmail.com>
This commit is contained in:
UniPM 2026-04-05 21:20:34 -05:00 committed by GitHub
parent 7251a8419f
commit 682989c8f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View file

@ -4,6 +4,7 @@ using Minecraft.Server.FourKit.Command;
using Minecraft.Server.FourKit.Entity;
using Minecraft.Server.FourKit.Event;
using Minecraft.Server.FourKit.Inventory;
using Minecraft.Server.FourKit.Plugin;
public static class FourKit
{
@ -351,4 +352,25 @@ public static class FourKit
{
return new Inventory.Inventory(title, type, type.getDefaultSize());
}
/// <summary>
/// Checks if the given plugin is loaded and returns it when applicable.
/// <para>
/// Please note that the name of the plugin is case-sensitive.
/// </para>
/// </summary>
/// <param name="name">Name of the plugin to check.</param>
/// <returns>Plugin if it exists, otherwise null</returns>
public static ServerPlugin? getPlugin(string name) {
var loadedPlugins = Minecraft.Server.FourKit.FourKitHost.getLoadedPlugins().Where(x => x.name == name);
if (loadedPlugins.Count() > 1) ServerLog.Warn("fourkit", $"More than one instance of a(n) '{name}' plugin.");
return loadedPlugins.FirstOrDefault();
}
/// <summary>
/// Gets a list of all currently loaded plugins.
/// </summary>
/// <returns>The array of plugins.</returns>
public static ServerPlugin[] getPlugins() => Minecraft.Server.FourKit.FourKitHost.getLoadedPlugins().ToArray(); // returns an array for better compatibility for bukkit->fourkit
}

View file

@ -9,6 +9,8 @@ public static partial class FourKitHost
{
private static PluginLoader? s_loader;
public static IReadOnlyList<Minecraft.Server.FourKit.Plugin.ServerPlugin> getLoadedPlugins() => s_loader?.Plugins ?? [];
[UnmanagedCallersOnly]
public static void Initialize()
{