From b2a1891f8d621dc09600adf607dd3bc07572884d Mon Sep 17 00:00:00 2001 From: Frank van der Heijden Date: Mon, 20 Dec 2021 19:03:47 +0100 Subject: [PATCH] Add protected-plugins config option --- .../commands/BukkitCommandServerUtils.java | 4 ++++ .../common/commands/CommandServerUtils.java | 24 +++++++++++++++++++ .../serverutils/common/config/MessageKey.java | 1 + Common/src/main/resources/config.json | 3 ++- Common/src/main/resources/messages.json | 3 ++- 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Bukkit/src/main/java/net/frankheijden/serverutils/bukkit/commands/BukkitCommandServerUtils.java b/Bukkit/src/main/java/net/frankheijden/serverutils/bukkit/commands/BukkitCommandServerUtils.java index e472e87..e83d9fc 100644 --- a/Bukkit/src/main/java/net/frankheijden/serverutils/bukkit/commands/BukkitCommandServerUtils.java +++ b/Bukkit/src/main/java/net/frankheijden/serverutils/bukkit/commands/BukkitCommandServerUtils.java @@ -105,6 +105,10 @@ public class BukkitCommandServerUtils extends CommandServerUtils plugins = Arrays.asList(context.get("plugins")); + if (checkProtectedPlugins(sender, plugins)) { + return; + } + if (checkDependingPlugins(context, sender, plugins, "disableplugin")) { return; } diff --git a/Common/src/main/java/net/frankheijden/serverutils/common/commands/CommandServerUtils.java b/Common/src/main/java/net/frankheijden/serverutils/common/commands/CommandServerUtils.java index de81bae..199f2b4 100644 --- a/Common/src/main/java/net/frankheijden/serverutils/common/commands/CommandServerUtils.java +++ b/Common/src/main/java/net/frankheijden/serverutils/common/commands/CommandServerUtils.java @@ -203,6 +203,10 @@ public abstract class CommandServerUtils plugins = Arrays.asList(context.get("plugins")); + if (checkProtectedPlugins(sender, plugins)) { + return; + } + if (checkDependingPlugins(context, sender, plugins, "unloadplugin")) { return; } @@ -224,6 +228,10 @@ public abstract class CommandServerUtils plugins = Arrays.asList(context.get("plugins")); + if (checkProtectedPlugins(sender, plugins)) { + return; + } + if (checkDependingPlugins(context, sender, plugins, "reloadplugin")) { return; } @@ -295,6 +303,22 @@ public abstract class CommandServerUtils plugins) { + List protectedPlugins = plugin.getConfigResource().getConfig().getStringList("protected-plugins"); + AbstractPluginManager pluginManager = plugin.getPluginManager(); + MessagesResource messagesResource = plugin.getMessagesResource(); + for (P plugin : plugins) { + String pluginId = pluginManager.getPluginId(plugin); + if (protectedPlugins.contains(pluginId)) { + sender.sendMessage(messagesResource.get(MessageKey.GENERIC_PROTECTED_PLUGIN).toComponent( + Template.of("plugin", pluginId) + )); + return true; + } + } + return false; + } + private void handleWatchPlugin(CommandContext context) { C sender = context.getSender(); List

plugins = Arrays.asList(context.get("plugins")); diff --git a/Common/src/main/java/net/frankheijden/serverutils/common/config/MessageKey.java b/Common/src/main/java/net/frankheijden/serverutils/common/config/MessageKey.java index 52362ce..c85f2df 100644 --- a/Common/src/main/java/net/frankheijden/serverutils/common/config/MessageKey.java +++ b/Common/src/main/java/net/frankheijden/serverutils/common/config/MessageKey.java @@ -21,6 +21,7 @@ public enum MessageKey implements PlaceholderConfigKey { GENERIC_INVALID_DESCRIPTION("generic.invalid-description"), GENERIC_UNKNOWN_DEPENDENCY("generic.unknown-dependency"), GENERIC_FILE_DELETED("generic.file-deleted"), + GENERIC_PROTECTED_PLUGIN("generic.protected-plugin"), DEPENDING_PLUGINS_PREFIX("depending-plugins.prefix"), DEPENDING_PLUGINS_FORMAT("depending-plugins.format"), DEPENDING_PLUGINS_SEPARATOR("depending-plugins.separator", false), diff --git a/Common/src/main/resources/config.json b/Common/src/main/resources/config.json index 2726c0c..4dcd789 100644 --- a/Common/src/main/resources/config.json +++ b/Common/src/main/resources/config.json @@ -12,5 +12,6 @@ "delay-ticks": 20, "plugins": [] }, - "hide-plugins-from-plugins-command": [] + "hide-plugins-from-plugins-command": [], + "protected-plugins": [] } diff --git a/Common/src/main/resources/messages.json b/Common/src/main/resources/messages.json index 455e15c..7d7ad43 100644 --- a/Common/src/main/resources/messages.json +++ b/Common/src/main/resources/messages.json @@ -12,7 +12,8 @@ "invalid-plugin": "Plugin is invalid!", "invalid-description": "Plugin has an invalid plugin description!", "unknown-dependency": "Plugin has an unknown dependency: !", - "file-deleted": "File of plugin has been deleted!" + "file-deleted": "File of plugin has been deleted!", + "protected-plugin": "Plugin is protected!" }, "reload": "Successfully reloaded ServerUtils configurations!", "serverutils-updater": "Loaded and enabled ServerUtilsUpdater. Completion can be monitored from the console, attempting restart now...",