diff options
author | Wesley Wolfe <weswolf@aol.com> | 2012-02-08 17:03:50 -0600 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-02-09 04:02:11 -0500 |
commit | 465818ef4220cb86604a31b1c9c7ad6db52e27d5 (patch) | |
tree | 8311659591f3995674d47845dd0ee5532f85c3b8 | |
parent | 73a1c478541dfeebf099af46d08031ee94eaf5d1 (diff) | |
download | bukkit-465818ef4220cb86604a31b1c9c7ad6db52e27d5.tar bukkit-465818ef4220cb86604a31b1c9c7ad6db52e27d5.tar.gz bukkit-465818ef4220cb86604a31b1c9c7ad6db52e27d5.tar.lz bukkit-465818ef4220cb86604a31b1c9c7ad6db52e27d5.tar.xz bukkit-465818ef4220cb86604a31b1c9c7ad6db52e27d5.zip |
[Bleeding] Implemented customizable permission messages.
-rw-r--r-- | src/main/java/org/bukkit/command/Command.java | 30 | ||||
-rw-r--r-- | src/main/java/org/bukkit/command/PluginCommandYamlParser.java | 5 |
2 files changed, 34 insertions, 1 deletions
diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java index 6ce96119..7c82fb0d 100644 --- a/src/main/java/org/bukkit/command/Command.java +++ b/src/main/java/org/bukkit/command/Command.java @@ -21,6 +21,7 @@ public abstract class Command { protected String description = ""; protected String usageMessage; private String permission; + private String permissionMessage; protected Command(String name) { this(name, "", "/" + name, new ArrayList<String>()); @@ -86,7 +87,14 @@ public abstract class Command { return true; } - target.sendMessage(ChatColor.RED + "I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error."); + if (permissionMessage == null) { + target.sendMessage(ChatColor.RED + "I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error."); + } else if (permissionMessage.length() != 0) { + for (String line : permissionMessage.replace("<permission>", permission).split("\n")) { + target.sendMessage(line); + } + } + return false; } @@ -172,6 +180,15 @@ public abstract class Command { } /** + * Returns a message to be displayed on a failed permission check for this command + * + * @return Permission check failed message + */ + public String getPermissionMessage() { + return permissionMessage; + } + + /** * Gets a brief description of this command * * @return Description of this command @@ -215,6 +232,17 @@ public abstract class Command { } /** + * Sets the message sent when a permission check fails + * + * @param permissionMessage New permission message, null to indicate default message, or an empty string to indicate no message + * @return This command object, for linking + */ + public Command setPermissionMessage(String permissionMessage) { + this.permissionMessage = permissionMessage; + return this; + } + + /** * Sets the example usage of this command * * @param usage New example usage diff --git a/src/main/java/org/bukkit/command/PluginCommandYamlParser.java b/src/main/java/org/bukkit/command/PluginCommandYamlParser.java index bce3f80c..e7feea49 100644 --- a/src/main/java/org/bukkit/command/PluginCommandYamlParser.java +++ b/src/main/java/org/bukkit/command/PluginCommandYamlParser.java @@ -27,6 +27,7 @@ public class PluginCommandYamlParser { Object usage = entry.getValue().get("usage"); Object aliases = entry.getValue().get("aliases"); Object permission = entry.getValue().get("permission"); + Object permissionMessage = entry.getValue().get("permission-message"); if (description != null) { newCmd.setDescription(description.toString()); @@ -54,6 +55,10 @@ public class PluginCommandYamlParser { newCmd.setPermission(permission.toString()); } + if (permissionMessage != null) { + newCmd.setPermissionMessage(permissionMessage.toString()); + } + pluginCmds.add(newCmd); } } |