mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-05-10 15:59:58 +00:00
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:
parent
7251a8419f
commit
682989c8f1
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue