From 682989c8f15099ba1eabe6119e0df00e327ae41c Mon Sep 17 00:00:00 2001 From: UniPM <76754418+UniversePM@users.noreply.github.com> Date: Sun, 5 Apr 2026 21:20:34 -0500 Subject: [PATCH] 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 --- Minecraft.Server.FourKit/FourKit.cs | 22 ++++++++++++++++++++++ Minecraft.Server.FourKit/FourKitHost.cs | 2 ++ 2 files changed, 24 insertions(+) diff --git a/Minecraft.Server.FourKit/FourKit.cs b/Minecraft.Server.FourKit/FourKit.cs index 2c3a11b7b..71ed26aa3 100644 --- a/Minecraft.Server.FourKit/FourKit.cs +++ b/Minecraft.Server.FourKit/FourKit.cs @@ -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()); } + + /// + /// Checks if the given plugin is loaded and returns it when applicable. + /// + /// Please note that the name of the plugin is case-sensitive. + /// + /// + /// Name of the plugin to check. + /// Plugin if it exists, otherwise null + 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(); + } + + /// + /// Gets a list of all currently loaded plugins. + /// + /// The array of plugins. + public static ServerPlugin[] getPlugins() => Minecraft.Server.FourKit.FourKitHost.getLoadedPlugins().ToArray(); // returns an array for better compatibility for bukkit->fourkit } diff --git a/Minecraft.Server.FourKit/FourKitHost.cs b/Minecraft.Server.FourKit/FourKitHost.cs index 72a55168c..613c6a564 100644 --- a/Minecraft.Server.FourKit/FourKitHost.cs +++ b/Minecraft.Server.FourKit/FourKitHost.cs @@ -9,6 +9,8 @@ public static partial class FourKitHost { private static PluginLoader? s_loader; + public static IReadOnlyList getLoadedPlugins() => s_loader?.Plugins ?? []; + [UnmanagedCallersOnly] public static void Initialize() {