summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorDinnerbone <dinnerbone@dinnerbone.com>2011-06-22 19:07:07 +0100
committerDinnerbone <dinnerbone@dinnerbone.com>2011-06-22 19:08:21 +0100
commitf71d7d0e9bb3d4968cd8384b10d2a000214f5edf (patch)
treed5734950147894f3be0c07ba5740a7cfe0880b3a /src/main/java/org
parentfaf2216d5c2c5df6833798d3749dd4bbdafbf2da (diff)
downloadbukkit-f71d7d0e9bb3d4968cd8384b10d2a000214f5edf.tar
bukkit-f71d7d0e9bb3d4968cd8384b10d2a000214f5edf.tar.gz
bukkit-f71d7d0e9bb3d4968cd8384b10d2a000214f5edf.tar.lz
bukkit-f71d7d0e9bb3d4968cd8384b10d2a000214f5edf.tar.xz
bukkit-f71d7d0e9bb3d4968cd8384b10d2a000214f5edf.zip
The server config can now specify aliases to multiple (or none) commands, for example "debug: [version, plugin]" to run both version and plugin, or "plugins: []" to disable the plugins command
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/bukkit/Server.java2
-rw-r--r--src/main/java/org/bukkit/command/MultipleCommandAlias.java25
-rw-r--r--src/main/java/org/bukkit/command/SimpleCommandMap.java32
3 files changed, 51 insertions, 8 deletions
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index abe41f05..124e5d08 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -270,7 +270,7 @@ public interface Server {
*
* @return Map of aliases to command names
*/
- public Map<String, String> getCommandAliases();
+ public Map<String, String[]> getCommandAliases();
/**
* Gets the radius, in blocks, around each worlds spawn point to protect
diff --git a/src/main/java/org/bukkit/command/MultipleCommandAlias.java b/src/main/java/org/bukkit/command/MultipleCommandAlias.java
new file mode 100644
index 00000000..e1474542
--- /dev/null
+++ b/src/main/java/org/bukkit/command/MultipleCommandAlias.java
@@ -0,0 +1,25 @@
+
+package org.bukkit.command;
+
+/**
+ * Represents a command that delegates to one or more other commands
+ */
+public class MultipleCommandAlias extends Command {
+ private Command[] commands;
+
+ public MultipleCommandAlias(String name, Command[] commands) {
+ super(name);
+ this.commands = commands;
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String commandLabel, String[] args) {
+ boolean result = false;
+
+ for (Command command : commands) {
+ result |= command.execute(sender, commandLabel, args);
+ }
+
+ return result;
+ }
+}
diff --git a/src/main/java/org/bukkit/command/SimpleCommandMap.java b/src/main/java/org/bukkit/command/SimpleCommandMap.java
index dfb066af..7a5e48fa 100644
--- a/src/main/java/org/bukkit/command/SimpleCommandMap.java
+++ b/src/main/java/org/bukkit/command/SimpleCommandMap.java
@@ -151,17 +151,35 @@ public final class SimpleCommandMap implements CommandMap {
}
public void registerServerAliases() {
- Map<String, String> values = server.getCommandAliases();
+ Map<String, String[]> values = server.getCommandAliases();
for (String alias : values.keySet()) {
- String target = values.get(alias);
- Command command = getCommand(target);
+ String[] targetNames = values.get(alias);
+ List<Command> targets = new ArrayList<Command>();
+ String bad = "";
- if (command != null) {
- // We register these as commands so they have absolute priority.
- knownCommands.put(alias.toLowerCase(), command);
+ for (String name : targetNames) {
+ Command command = getCommand(name);
+
+ if (command == null) {
+ if (bad.length() > 0) {
+ bad += ", ";
+ }
+ } else {
+ targets.add(command);
+ }
+ }
+
+ // We register these as commands so they have absolute priority.
+
+ if (targets.size() > 0) {
+ knownCommands.put(alias.toLowerCase(), new MultipleCommandAlias(alias.toLowerCase(), targets.toArray(new Command[0])));
} else {
- server.getLogger().warning("Could not register custom alias '" + alias + "' to command '" + target + "' because the command does not exist.");
+ knownCommands.remove(alias.toLowerCase());
+ }
+
+ if (bad.length() > 0) {
+ server.getLogger().warning("The following command(s) could not be aliased under '" + alias + "' because they do not exist: " + bad);
}
}
}