From b900116cc89bc0ee55d4cd856dadce60b46e3701 Mon Sep 17 00:00:00 2001 From: zenexer Date: Fri, 15 Apr 2011 01:41:42 +0000 Subject: [PATCH] Added overridden-commands. Commands beginning with /e will also give Essentials precedence. git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1193 e251c2fe-e539-e718-e476-b85c1f46cddb --- .../nbproject/private/private.properties | 1 + Essentials/nbproject/private/private.xml | 4 ++ .../com/earth2me/essentials/Essentials.java | 37 ++++++++++--------- .../src/com/earth2me/essentials/Settings.java | 17 ++++++++- Essentials/src/config.yml | 12 ++++++ 5 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 Essentials/nbproject/private/private.properties create mode 100644 Essentials/nbproject/private/private.xml diff --git a/Essentials/nbproject/private/private.properties b/Essentials/nbproject/private/private.properties new file mode 100644 index 000000000..94183418a --- /dev/null +++ b/Essentials/nbproject/private/private.properties @@ -0,0 +1 @@ +user.properties.file=C:\\Users\\Paul\\.netbeans\\7.0beta2\\build.properties diff --git a/Essentials/nbproject/private/private.xml b/Essentials/nbproject/private/private.xml new file mode 100644 index 000000000..cc2c0e57c --- /dev/null +++ b/Essentials/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 524be35e0..a373f55e9 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -496,31 +496,34 @@ public class Essentials extends JavaPlugin public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { // Allow plugins to override the command via onCommand - for (Plugin p : getServer().getPluginManager().getPlugins()) + if (!getSettings().isCommandOverridden(command.getName()) && !commandLabel.startsWith("e")) { - if (p == this) - continue; + for (Plugin p : getServer().getPluginManager().getPlugins()) + { + if (p == this) + continue; - PluginDescriptionFile desc = p.getDescription(); - if (desc == null) - continue; + PluginDescriptionFile desc = p.getDescription(); + if (desc == null) + continue; - if (desc.getName() == null) - continue; + if (desc.getName() == null) + continue; - if (!(desc.getCommands() instanceof Map)) - continue; + if (!(desc.getCommands() instanceof Map)) + continue; - Map cmds = (Map)desc.getCommands(); - if (!cmds.containsKey(command.getName())) - continue; + Map cmds = (Map)desc.getCommands(); + if (!cmds.containsKey(command.getName())) + continue; - PluginCommand pcmd = getServer().getPluginCommand(desc.getName() + ":" + commandLabel); + PluginCommand pcmd = getServer().getPluginCommand(desc.getName() + ":" + commandLabel); - if (pcmd == null) - continue; + if (pcmd == null) + continue; - return getServer().getPluginCommand(p.getDescription().getName() + ":" + commandLabel).execute(sender, commandLabel, args); + return getServer().getPluginCommand(p.getDescription().getName() + ":" + commandLabel).execute(sender, commandLabel, args); + } } try diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index 3d2b55739..6d6ee3225 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -98,6 +98,19 @@ public class Settings implements IConf return config.getBoolean("restrict-" + label.toLowerCase(), false); } + public boolean isCommandOverridden(String name) + { + List defaultList = new ArrayList(1); + defaultList.add("god"); + for (String c : config.getStringList("overridden-commands", defaultList)) + { + if (!c.equalsIgnoreCase(name)) + continue; + return true; + } + return config.getBoolean("override-" + name.toLowerCase(), false); + } + public int getCommandCost(IEssentialsCommand cmd) { return getCommandCost(cmd.getName()); @@ -436,12 +449,12 @@ public class Settings implements IConf return epBreakList; } - public Boolean spawnIfNoHome() + public boolean spawnIfNoHome() { return config.getBoolean("spawn-if-no-home", false); } - public Boolean warnOnBuildDisallow() + public boolean warnOnBuildDisallow() { return config.getBoolean("warn-on-build-disallow", false); } diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 11d3c323e..a8bbadb0d 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -74,12 +74,24 @@ motd: - '&cWelcome, {PLAYER}&c!' - '&fType &c/help&f for a list of commands.' - 'Currently online: {PLAYERLIST}' + - 'Did you know that you can make [Disposal] signs with Essentials?' # The server rules, available by typing /rules rules: - '[1] Be respectful' - '[2] Be ethical' - '[3] Use common sense' + +# When a command conflicts with another plugin, by default, Essentials will try to force the OTHER plugin to take +# priority. If a command is in this list, Essentials will try to give ITSELF priority. This does not always work: +# usually whichever plugin was updated most recently wins out. However, the full name of the command will always work. +# For example, if WorldGuard and Essentials are both enabled, and WorldGuard takes control over /god, /essentials:god +# will still map to Essentials, whereas it might normally get forced upon WorldGuard. Commands prefixed with an "e", +# such as /egod, will always grant Essentials priority. +# Because WorldGuard's /god is broken/unreliable, we should try to take priority over /god. If this doesn't work, use +# /essentials:god or /egod. Do NOT use WorldGuard's /god, or you will likely be stuck in god mode. +overridden-commands: + - god # Disabled commands will be completelly unavailable on the server. disabled-commands: