Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PluginCommandYamlParser.java
1 package org.bukkit.command;
2 
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.Map;
6 import java.util.Map.Entry;
7 
8 import org.bukkit.Bukkit;
9 import org.bukkit.plugin.Plugin;
10 
12 
13  public static List<Command> parse(Plugin plugin) {
14  List<Command> pluginCmds = new ArrayList<Command>();
15 
16  Map<String, Map<String, Object>> map = plugin.getDescription().getCommands();
17 
18  if (map == null) {
19  return pluginCmds;
20  }
21 
22  for (Entry<String, Map<String, Object>> entry : map.entrySet()) {
23  if (entry.getKey().contains(":")) {
24  Bukkit.getServer().getLogger().severe("Could not load command " + entry.getKey() + " for plugin " + plugin.getName() + ": Illegal Characters");
25  continue;
26  }
27  Command newCmd = new PluginCommand(entry.getKey(), plugin);
28  Object description = entry.getValue().get("description");
29  Object usage = entry.getValue().get("usage");
30  Object aliases = entry.getValue().get("aliases");
31  Object permission = entry.getValue().get("permission");
32  Object permissionMessage = entry.getValue().get("permission-message");
33 
34  if (description != null) {
35  newCmd.setDescription(description.toString());
36  }
37 
38  if (usage != null) {
39  newCmd.setUsage(usage.toString());
40  }
41 
42  if (aliases != null) {
43  List<String> aliasList = new ArrayList<String>();
44 
45  if (aliases instanceof List) {
46  for (Object o : (List<?>) aliases) {
47  if (o.toString().contains(":")) {
48  Bukkit.getServer().getLogger().severe("Could not load alias " + o.toString() + " for plugin " + plugin.getName() + ": Illegal Characters");
49  continue;
50  }
51  aliasList.add(o.toString());
52  }
53  } else {
54  if (aliases.toString().contains(":")) {
55  Bukkit.getServer().getLogger().severe("Could not load alias " + aliases.toString() + " for plugin " + plugin.getName() + ": Illegal Characters");
56  } else {
57  aliasList.add(aliases.toString());
58  }
59  }
60 
61  newCmd.setAliases(aliasList);
62  }
63 
64  if (permission != null) {
65  newCmd.setPermission(permission.toString());
66  }
67 
68  if (permissionMessage != null) {
69  newCmd.setPermissionMessage(permissionMessage.toString());
70  }
71 
72  pluginCmds.add(newCmd);
73  }
74  return pluginCmds;
75  }
76 }
Command setDescription(String description)
Command setPermissionMessage(String permissionMessage)
Command setAliases(List< String > aliases)
Command setUsage(String usage)
void setPermission(String permission)
static Server getServer()
Definition: Bukkit.java:50
PluginDescriptionFile getDescription()
Map< String, Map< String, Object > > getCommands()
Logger getLogger()