[Bleeding] Fixed a StackOverflowError with command alias handling for Help. Addresses BUKKIT-1253

Dieser Commit ist enthalten in:
zml2008 2012-03-20 19:12:14 -07:00 committet von EvilSeph
Ursprung 8aee4c3f56
Commit 31b1bc02ca
2 geänderte Dateien mit 13 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.help; package org.bukkit.craftbukkit.help;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.help.HelpMap; import org.bukkit.help.HelpMap;
@ -14,6 +15,7 @@ public class CommandAliasHelpTopic extends HelpTopic {
this.aliasFor = aliasFor.startsWith("/") ? aliasFor : "/" + aliasFor; this.aliasFor = aliasFor.startsWith("/") ? aliasFor : "/" + aliasFor;
this.helpMap = helpMap; this.helpMap = helpMap;
this.name = alias.startsWith("/") ? alias : "/" + alias; this.name = alias.startsWith("/") ? alias : "/" + alias;
Validate.isTrue(!this.name.equals(this.aliasFor), "Command " + this.name + " cannot be alias for itself");
this.shortText = ChatColor.YELLOW + "Alias for " + ChatColor.WHITE + this.aliasFor; this.shortText = ChatColor.YELLOW + "Alias for " + ChatColor.WHITE + this.aliasFor;
} }

Datei anzeigen

@ -16,10 +16,10 @@ import java.util.*;
* Standard implementation of {@link HelpMap} for CraftBukkit servers. * Standard implementation of {@link HelpMap} for CraftBukkit servers.
*/ */
public class SimpleHelpMap implements HelpMap { public class SimpleHelpMap implements HelpMap {
private final HelpTopic defaultTopic; private final HelpTopic defaultTopic;
private final Map<String, HelpTopic> helpTopics; private final Map<String, HelpTopic> helpTopics;
private final Set<HelpTopic> pluginIndexes; private final Set<HelpTopic> pluginIndexes;
private final Map<Class, HelpTopicFactory<Command>> topicFactoryMap; private final Map<Class, HelpTopicFactory<Command>> topicFactoryMap;
private final CraftServer server; private final CraftServer server;
private HelpYamlReader yaml; private HelpYamlReader yaml;
@ -40,7 +40,7 @@ public class SimpleHelpMap implements HelpMap {
registerHelpTopicFactory(MultipleCommandAlias.class, new MultipleCommandAliasHelpTopicFactory()); registerHelpTopicFactory(MultipleCommandAlias.class, new MultipleCommandAliasHelpTopicFactory());
} }
public synchronized HelpTopic getHelpTopic(String topicName) { public synchronized HelpTopic getHelpTopic(String topicName) {
if (topicName.equals("")) { if (topicName.equals("")) {
return defaultTopic; return defaultTopic;
@ -112,14 +112,16 @@ public class SimpleHelpMap implements HelpMap {
} }
addTopic(new GenericCommandHelpTopic(command)); addTopic(new GenericCommandHelpTopic(command));
} }
// Initialize command alias help topics // Initialize command alias help topics
for (Command command : server.getCommandMap().getCommands()) { for (Command command : server.getCommandMap().getCommands()) {
if (commandInIgnoredPlugin(command, ignoredPlugins)) { if (commandInIgnoredPlugin(command, ignoredPlugins)) {
continue; continue;
} }
for (String alias : command.getAliases()) { for (String alias : command.getAliases()) {
addTopic(new CommandAliasHelpTopic(alias, command.getLabel(), this)); if (!helpTopics.containsKey("/" + alias)) {
addTopic(new CommandAliasHelpTopic("/" + alias, "/" + command.getLabel(), this));
}
} }
} }
@ -132,7 +134,7 @@ public class SimpleHelpMap implements HelpMap {
// Add alias sub-index // Add alias sub-index
addTopic(new IndexHelpTopic("Aliases", "Lists command aliases", null, Collections2.filter(helpTopics.values(), Predicates.instanceOf(CommandAliasHelpTopic.class)))); addTopic(new IndexHelpTopic("Aliases", "Lists command aliases", null, Collections2.filter(helpTopics.values(), Predicates.instanceOf(CommandAliasHelpTopic.class))));
// Initialize plugin-level sub-topics // Initialize plugin-level sub-topics
Map<String, Set<HelpTopic>> pluginIndexes = new HashMap<String, Set<HelpTopic>>(); Map<String, Set<HelpTopic>> pluginIndexes = new HashMap<String, Set<HelpTopic>>();
fillPluginIndexes(pluginIndexes, server.getCommandMap().getCommands()); fillPluginIndexes(pluginIndexes, server.getCommandMap().getCommands());
@ -152,7 +154,7 @@ public class SimpleHelpMap implements HelpMap {
} }
} }
} }
private void fillPluginIndexes(Map<String, Set<HelpTopic>> pluginIndexes, Collection<? extends Command> commands) { private void fillPluginIndexes(Map<String, Set<HelpTopic>> pluginIndexes, Collection<? extends Command> commands) {
for (Command command : commands) { for (Command command : commands) {
String pluginName = getCommandPluginName(command); String pluginName = getCommandPluginName(command);
@ -167,7 +169,7 @@ public class SimpleHelpMap implements HelpMap {
} }
} }
} }
private String getCommandPluginName(Command command) { private String getCommandPluginName(Command command) {
if (command instanceof BukkitCommand || command instanceof VanillaCommand) { if (command instanceof BukkitCommand || command instanceof VanillaCommand) {
return "Bukkit"; return "Bukkit";
@ -177,7 +179,7 @@ public class SimpleHelpMap implements HelpMap {
} }
return null; return null;
} }
private boolean commandInIgnoredPlugin(Command command, Set<String> ignoredPlugins) { private boolean commandInIgnoredPlugin(Command command, Set<String> ignoredPlugins) {
if ((command instanceof BukkitCommand || command instanceof VanillaCommand) && ignoredPlugins.contains("Bukkit")) { if ((command instanceof BukkitCommand || command instanceof VanillaCommand) && ignoredPlugins.contains("Bukkit")) {
return true; return true;