Updated commands to have optional aliases, and to fallback to /pluginName:cmdName on name conflict.

By: VictorD <victor.danell@gmail.com>
This commit is contained in:
Bukkit/Spigot
2011-01-18 01:12:50 +01:00
parent b46210453c
commit ab6f5d4bc2
11 changed files with 233 additions and 161 deletions

View File

@@ -0,0 +1,51 @@
package org.bukkit.command;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.plugin.Plugin;
public class PluginCommandYamlParser {
public static List<Command> parse(Plugin plugin) {
List<Command> pluginCmds = new ArrayList<Command>();
Object object = plugin.getDescription().getCommands();
if (object == null)
return pluginCmds;
@SuppressWarnings("unchecked")
Map<String, Map<String, Object>> map = (Map<String, Map<String, Object>>)object;
if (map != null) {
for(Entry<String, Map<String, Object>> entry : map.entrySet()) {
Command newCmd = new PluginCommand(entry.getKey(),plugin);
Object description = entry.getValue().get("description");
Object usage = entry.getValue().get("usage");
Object aliases = entry.getValue().get("aliases");
if (description != null)
newCmd.setTooltip(description.toString());
if (usage != null) {
newCmd.setUsage(usage.toString());
}
if (aliases != null) {
List<String> aliasList = new ArrayList<String>();
for(String a : aliases.toString().split(",")) {
aliasList.add(a);
}
newCmd.setAliases(aliasList);
}
pluginCmds.add(newCmd);
}
}
return pluginCmds;
}
}