Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
1package org.bukkit.command;
2
3import org.bukkit.plugin.Plugin;
4
5import java.util.ArrayList;
6import java.util.List;
7import java.util.Map;
8import java.util.Map.Entry;
9
10public class PluginCommandYamlParser {
11
12 @SuppressWarnings("unchecked")
13 public static List<Command> parse(Plugin plugin) {
14 List<Command> pluginCmds = new ArrayList<Command>();
15 Object object = plugin.getDescription().getCommands();
16
17 if (object == null) {
18 return pluginCmds;
19 }
20
21 Map<String, Map<String, Object>> map = (Map<String, Map<String, Object>>) object;
22
23 if (map != null) {
24 for (Entry<String, Map<String, Object>> entry : map.entrySet()) {
25 Command newCmd = new PluginCommand(entry.getKey(), plugin);
26 Object description = entry.getValue().get("description");
27 Object usage = entry.getValue().get("usage");
28 Object aliases = entry.getValue().get("aliases");
29 Object permission = entry.getValue().get("permission");
30 Object isHidden = entry.getValue().get("hidden");
31
32 if (isHidden != null) {
33 newCmd.setHidden(String.valueOf(isHidden).equalsIgnoreCase("true"));
34 }
35
36 if (description != null) {
37 newCmd.setDescription(description.toString());
38 }
39
40 if (usage != null) {
41 newCmd.setUsage(usage.toString());
42 }
43
44 if (aliases != null) {
45 List<String> aliasList = new ArrayList<String>();
46
47 if (aliases instanceof List) {
48 for (Object o : (List<Object>) aliases) {
49 aliasList.add(o.toString());
50 }
51 } else {
52 aliasList.add(aliases.toString());
53 }
54
55 newCmd.setAliases(aliasList);
56 }
57
58 if (permission != null) {
59 newCmd.setPermission(permission.toString());
60 }
61
62 pluginCmds.add(newCmd);
63 }
64 }
65 return pluginCmds;
66 }
67}