Merge pull request #42 from FrankHeijden/feature/protected-plugins

Add protected-plugins config option
This commit is contained in:
Frank van der Heijden 2021-12-20 19:12:25 +01:00 committed by GitHub
commit 1e9d98eb4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 2 deletions

View file

@ -105,6 +105,10 @@ public class BukkitCommandServerUtils extends CommandServerUtils<BukkitPlugin, P
BukkitAudience sender = context.getSender();
List<Plugin> plugins = Arrays.asList(context.get("plugins"));
if (checkProtectedPlugins(sender, plugins)) {
return;
}
if (checkDependingPlugins(context, sender, plugins, "disableplugin")) {
return;
}

View file

@ -203,6 +203,10 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
C sender = context.getSender();
List<P> 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<U extends ServerUtilsPlugin<P, ?, C, ?,
C sender = context.getSender();
List<P> 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<U extends ServerUtilsPlugin<P, ?, C, ?,
return false;
}
protected boolean checkProtectedPlugins(C sender, List<P> plugins) {
List<String> protectedPlugins = plugin.getConfigResource().getConfig().getStringList("protected-plugins");
AbstractPluginManager<P, ?> 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<C> context) {
C sender = context.getSender();
List<P> plugins = Arrays.asList(context.get("plugins"));

View file

@ -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),

View file

@ -12,5 +12,6 @@
"delay-ticks": 20,
"plugins": []
},
"hide-plugins-from-plugins-command": []
"hide-plugins-from-plugins-command": [],
"protected-plugins": []
}

View file

@ -12,7 +12,8 @@
"invalid-plugin": "<red>Plugin <dark_red><plugin></dark_red> is invalid!",
"invalid-description": "<red>Plugin <dark_red><plugin></dark_red> has an invalid plugin description!",
"unknown-dependency": "<red>Plugin <dark_red><plugin></dark_red> has an unknown dependency: <dark_red><dependency><red>!",
"file-deleted": "<red>File of plugin <dark_red><plugin></dark_red> has been deleted!"
"file-deleted": "<red>File of plugin <dark_red><plugin></dark_red> has been deleted!",
"protected-plugin": "<red>Plugin <dark_red><plugin></dark_red> is protected!"
},
"reload": "<dark_aqua>Successfully reloaded <aqua>ServerUtils configurations</aqua>!",
"serverutils-updater": "<dark_aqua>Loaded and enabled ServerUtilsUpdater. Completion can be monitored from the console, attempting restart now...",