001 package org.bukkit.command; 002 003 import java.util.ArrayList; 004 import java.util.List; 005 import java.util.Map; 006 import java.util.Map.Entry; 007 008 import org.bukkit.Bukkit; 009 import org.bukkit.plugin.Plugin; 010 011 public class PluginCommandYamlParser { 012 013 public static List<Command> parse(Plugin plugin) { 014 List<Command> pluginCmds = new ArrayList<Command>(); 015 016 Map<String, Map<String, Object>> map = plugin.getDescription().getCommands(); 017 018 if (map == null) { 019 return pluginCmds; 020 } 021 022 for (Entry<String, Map<String, Object>> entry : map.entrySet()) { 023 if (entry.getKey().contains(":")) { 024 Bukkit.getServer().getLogger().severe("Could not load command " + entry.getKey() + " for plugin " + plugin.getName() + ": Illegal Characters"); 025 continue; 026 } 027 Command newCmd = new PluginCommand(entry.getKey(), plugin); 028 Object description = entry.getValue().get("description"); 029 Object usage = entry.getValue().get("usage"); 030 Object aliases = entry.getValue().get("aliases"); 031 Object permission = entry.getValue().get("permission"); 032 Object permissionMessage = entry.getValue().get("permission-message"); 033 034 if (description != null) { 035 newCmd.setDescription(description.toString()); 036 } 037 038 if (usage != null) { 039 newCmd.setUsage(usage.toString()); 040 } 041 042 if (aliases != null) { 043 List<String> aliasList = new ArrayList<String>(); 044 045 if (aliases instanceof List) { 046 for (Object o : (List<?>) aliases) { 047 if (o.toString().contains(":")) { 048 Bukkit.getServer().getLogger().severe("Could not load alias " + o.toString() + " for plugin " + plugin.getName() + ": Illegal Characters"); 049 continue; 050 } 051 aliasList.add(o.toString()); 052 } 053 } else { 054 if (aliases.toString().contains(":")) { 055 Bukkit.getServer().getLogger().severe("Could not load alias " + aliases.toString() + " for plugin " + plugin.getName() + ": Illegal Characters"); 056 } else { 057 aliasList.add(aliases.toString()); 058 } 059 } 060 061 newCmd.setAliases(aliasList); 062 } 063 064 if (permission != null) { 065 newCmd.setPermission(permission.toString()); 066 } 067 068 if (permissionMessage != null) { 069 newCmd.setPermissionMessage(permissionMessage.toString()); 070 } 071 072 pluginCmds.add(newCmd); 073 } 074 return pluginCmds; 075 } 076 }