Merge pull request #42 from FrankHeijden/feature/protected-plugins
Add protected-plugins config option
This commit is contained in:
commit
1e9d98eb4e
5 changed files with 33 additions and 2 deletions
|
|
@ -105,6 +105,10 @@ public class BukkitCommandServerUtils extends CommandServerUtils<BukkitPlugin, P
|
||||||
BukkitAudience sender = context.getSender();
|
BukkitAudience sender = context.getSender();
|
||||||
List<Plugin> plugins = Arrays.asList(context.get("plugins"));
|
List<Plugin> plugins = Arrays.asList(context.get("plugins"));
|
||||||
|
|
||||||
|
if (checkProtectedPlugins(sender, plugins)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (checkDependingPlugins(context, sender, plugins, "disableplugin")) {
|
if (checkDependingPlugins(context, sender, plugins, "disableplugin")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -203,6 +203,10 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
||||||
C sender = context.getSender();
|
C sender = context.getSender();
|
||||||
List<P> plugins = Arrays.asList(context.get("plugins"));
|
List<P> plugins = Arrays.asList(context.get("plugins"));
|
||||||
|
|
||||||
|
if (checkProtectedPlugins(sender, plugins)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (checkDependingPlugins(context, sender, plugins, "unloadplugin")) {
|
if (checkDependingPlugins(context, sender, plugins, "unloadplugin")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -224,6 +228,10 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
||||||
C sender = context.getSender();
|
C sender = context.getSender();
|
||||||
List<P> plugins = Arrays.asList(context.get("plugins"));
|
List<P> plugins = Arrays.asList(context.get("plugins"));
|
||||||
|
|
||||||
|
if (checkProtectedPlugins(sender, plugins)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (checkDependingPlugins(context, sender, plugins, "reloadplugin")) {
|
if (checkDependingPlugins(context, sender, plugins, "reloadplugin")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -295,6 +303,22 @@ public abstract class CommandServerUtils<U extends ServerUtilsPlugin<P, ?, C, ?,
|
||||||
return false;
|
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) {
|
private void handleWatchPlugin(CommandContext<C> context) {
|
||||||
C sender = context.getSender();
|
C sender = context.getSender();
|
||||||
List<P> plugins = Arrays.asList(context.get("plugins"));
|
List<P> plugins = Arrays.asList(context.get("plugins"));
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ public enum MessageKey implements PlaceholderConfigKey {
|
||||||
GENERIC_INVALID_DESCRIPTION("generic.invalid-description"),
|
GENERIC_INVALID_DESCRIPTION("generic.invalid-description"),
|
||||||
GENERIC_UNKNOWN_DEPENDENCY("generic.unknown-dependency"),
|
GENERIC_UNKNOWN_DEPENDENCY("generic.unknown-dependency"),
|
||||||
GENERIC_FILE_DELETED("generic.file-deleted"),
|
GENERIC_FILE_DELETED("generic.file-deleted"),
|
||||||
|
GENERIC_PROTECTED_PLUGIN("generic.protected-plugin"),
|
||||||
DEPENDING_PLUGINS_PREFIX("depending-plugins.prefix"),
|
DEPENDING_PLUGINS_PREFIX("depending-plugins.prefix"),
|
||||||
DEPENDING_PLUGINS_FORMAT("depending-plugins.format"),
|
DEPENDING_PLUGINS_FORMAT("depending-plugins.format"),
|
||||||
DEPENDING_PLUGINS_SEPARATOR("depending-plugins.separator", false),
|
DEPENDING_PLUGINS_SEPARATOR("depending-plugins.separator", false),
|
||||||
|
|
|
||||||
|
|
@ -12,5 +12,6 @@
|
||||||
"delay-ticks": 20,
|
"delay-ticks": 20,
|
||||||
"plugins": []
|
"plugins": []
|
||||||
},
|
},
|
||||||
"hide-plugins-from-plugins-command": []
|
"hide-plugins-from-plugins-command": [],
|
||||||
|
"protected-plugins": []
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@
|
||||||
"invalid-plugin": "<red>Plugin <dark_red><plugin></dark_red> is invalid!",
|
"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!",
|
"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>!",
|
"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>!",
|
"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...",
|
"serverutils-updater": "<dark_aqua>Loaded and enabled ServerUtilsUpdater. Completion can be monitored from the console, attempting restart now...",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue