From eefcef54802c2313bbd2123d88f3ffa469622635 Mon Sep 17 00:00:00 2001 From: Erik Broes Date: Thu, 13 Oct 2011 18:27:34 +0200 Subject: Revert "Added the ability to register commands dynamically." This reverts commit 737d6347b1d74e13191df7c521d8db30fa174c9b. Because this is *NOT* how it should be. --- .../java/org/bukkit/command/CommandDefinition.java | 133 --------------------- .../java/org/bukkit/command/PluginCommandUtil.java | 89 -------------- .../bukkit/command/PluginCommandYamlParser.java | 62 ++++++++++ src/main/java/org/bukkit/plugin/PluginManager.java | 11 -- .../org/bukkit/plugin/SimplePluginManager.java | 11 +- 5 files changed, 64 insertions(+), 242 deletions(-) delete mode 100644 src/main/java/org/bukkit/command/CommandDefinition.java delete mode 100644 src/main/java/org/bukkit/command/PluginCommandUtil.java create mode 100644 src/main/java/org/bukkit/command/PluginCommandYamlParser.java (limited to 'src/main/java/org') diff --git a/src/main/java/org/bukkit/command/CommandDefinition.java b/src/main/java/org/bukkit/command/CommandDefinition.java deleted file mode 100644 index 2e384c6b..00000000 --- a/src/main/java/org/bukkit/command/CommandDefinition.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.bukkit.command; - -import java.util.ArrayList; -import java.util.List; - -/** - * Represents a command that can be registered dynamically. - * - * @author sk89q - */ -public class CommandDefinition { - - private String name; - private String description; - private String usage; - private List aliases = new ArrayList(); - private String permission; - - /** - * Construct the command with a given name. - * - * @param name The command name (without a preceding /) - */ - public CommandDefinition(String name) { - setName(name); - } - - /** - * Construct the command with a given name and description. - * - * @param name The command name - * @param description The command description (without a preceding /) - */ - public CommandDefinition(String name, String description) { - setName(name); - setDescription(description); - } - - /** - * Get the name. - * - * @return Command name - */ - public String getName() { - return name; - } - - /** - * Sets the command name. - * - * @param name Command name - */ - public void setName(String name) { - if (name == null) { - throw new IllegalArgumentException("Cannot have a null command name"); - } - - this.name = name; - } - - /** - * Get the description. - * - * @return Command description, possibly null - */ - public String getDescription() { - return description; - } - - /** - * Sets the command description. - * - * @param name Command description, possibly null - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * Get the usage string. - * - * @return Command description, possibly null - */ - public String getUsage() { - return usage; - } - - /** - * Sets the command usage string. - * - * @param name Command usage string, possibly null - */ - public void setUsage(String usage) { - this.usage = usage; - } - - /** - * Get the list of aliases. - * - * @return List of aliases, possibly null - */ - public List getAliases() { - return aliases; - } - - /** - * Set the list of aliases. - * - * @param aliases List of aliases - */ - public void setAliases(List aliases) { - this.aliases = aliases; - } - - /** - * Get the permission. - * - * @return Command permission, possibly null - */ - public String getPermission() { - return permission; - } - - /** - * Sets the permission. - * - * @param name Command permission, possibly null - */ - public void setPermission(String permission) { - this.permission = permission; - } - -} diff --git a/src/main/java/org/bukkit/command/PluginCommandUtil.java b/src/main/java/org/bukkit/command/PluginCommandUtil.java deleted file mode 100644 index cc3b47d8..00000000 --- a/src/main/java/org/bukkit/command/PluginCommandUtil.java +++ /dev/null @@ -1,89 +0,0 @@ -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 PluginCommandUtil { - - @SuppressWarnings("unchecked") - public static List parse(Plugin plugin) { - List pluginCmds = new ArrayList(); - Object object = plugin.getDescription().getCommands(); - - if (object == null) { - return pluginCmds; - } - - Map> map = (Map>) object; - - if (map != null) { - for (Entry> 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"); - Object permission = entry.getValue().get("permission"); - - if (description != null) { - newCmd.setDescription(description.toString()); - } - - if (usage != null) { - newCmd.setUsage(usage.toString()); - } - - if (aliases != null) { - List aliasList = new ArrayList(); - - if (aliases instanceof List) { - for (Object o : (List) aliases) { - aliasList.add(o.toString()); - } - } else { - aliasList.add(aliases.toString()); - } - - newCmd.setAliases(aliasList); - } - - if (permission != null) { - newCmd.setPermission(permission.toString()); - } - - pluginCmds.add(newCmd); - } - } - return pluginCmds; - } - - public static Command parse(CommandDefinition command, Plugin plugin) { - Command newCmd = new PluginCommand(command.getName(), plugin); - String description = command.getDescription(); - String usage = command.getUsage(); - List aliases = command.getAliases(); - String permission = command.getPermission(); - - if (description != null) { - newCmd.setDescription(description); - } - - if (usage != null) { - newCmd.setUsage(usage); - } - - if (aliases != null) { - newCmd.setAliases(aliases); - } - - if (permission != null) { - newCmd.setPermission(permission); - } - - return newCmd; - } - -} diff --git a/src/main/java/org/bukkit/command/PluginCommandYamlParser.java b/src/main/java/org/bukkit/command/PluginCommandYamlParser.java new file mode 100644 index 00000000..bce3f80c --- /dev/null +++ b/src/main/java/org/bukkit/command/PluginCommandYamlParser.java @@ -0,0 +1,62 @@ +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 { + + @SuppressWarnings("unchecked") + public static List parse(Plugin plugin) { + List pluginCmds = new ArrayList(); + Object object = plugin.getDescription().getCommands(); + + if (object == null) { + return pluginCmds; + } + + Map> map = (Map>) object; + + if (map != null) { + for (Entry> 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"); + Object permission = entry.getValue().get("permission"); + + if (description != null) { + newCmd.setDescription(description.toString()); + } + + if (usage != null) { + newCmd.setUsage(usage.toString()); + } + + if (aliases != null) { + List aliasList = new ArrayList(); + + if (aliases instanceof List) { + for (Object o : (List) aliases) { + aliasList.add(o.toString()); + } + } else { + aliasList.add(aliases.toString()); + } + + newCmd.setAliases(aliasList); + } + + if (permission != null) { + newCmd.setPermission(permission.toString()); + } + + pluginCmds.add(newCmd); + } + } + return pluginCmds; + } +} diff --git a/src/main/java/org/bukkit/plugin/PluginManager.java b/src/main/java/org/bukkit/plugin/PluginManager.java index 0b477722..7d7f1c2b 100644 --- a/src/main/java/org/bukkit/plugin/PluginManager.java +++ b/src/main/java/org/bukkit/plugin/PluginManager.java @@ -3,9 +3,6 @@ package org.bukkit.plugin; import java.io.File; import java.util.Set; -import org.bukkit.command.CommandDefinition; -import org.bukkit.command.CommandMap; -import org.bukkit.command.PluginCommand; import org.bukkit.event.Event; import org.bukkit.event.Event.Priority; import org.bukkit.event.Listener; @@ -255,12 +252,4 @@ public interface PluginManager { * @return Set containing all current registered permissions */ public Set getPermissions(); - - /** - * Registers a plugin command dynamically. - * - * @param command Command definition to use - * @param plugin Plugin to associate it with - */ - public void registerCommand(CommandDefinition command, Plugin plugin); } diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java index aa401cb0..a79c3583 100644 --- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java @@ -23,10 +23,7 @@ import java.util.regex.Matcher; import org.bukkit.Server; import java.util.regex.Pattern; import org.bukkit.command.Command; -import org.bukkit.command.CommandMap; -import org.bukkit.command.CommandDefinition; -import org.bukkit.command.PluginCommand; -import org.bukkit.command.PluginCommandUtil; +import org.bukkit.command.PluginCommandYamlParser; import org.bukkit.command.SimpleCommandMap; import org.bukkit.event.Event; @@ -273,7 +270,7 @@ public final class SimplePluginManager implements PluginManager { public void enablePlugin(final Plugin plugin) { if (!plugin.isEnabled()) { - List pluginCommands = PluginCommandUtil.parse(plugin); + List pluginCommands = PluginCommandYamlParser.parse(plugin); if (!pluginCommands.isEmpty()) { commandMap.registerAll(plugin.getDescription().getName(), pluginCommands); @@ -543,8 +540,4 @@ public final class SimplePluginManager implements PluginManager { public Set getPermissions() { return new HashSet(permissions.values()); } - - public void registerCommand(CommandDefinition command, Plugin plugin) { - commandMap.register(plugin.getDescription().getName(), PluginCommandUtil.parse(command, plugin)); - } } -- cgit v1.2.3