From 31b1bc02ca968d7282c7fdc734e67b23d6ee93e5 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Tue, 20 Mar 2012 19:12:14 -0700 Subject: [PATCH] [Bleeding] Fixed a StackOverflowError with command alias handling for Help. Addresses BUKKIT-1253 --- .../help/CommandAliasHelpTopic.java | 2 ++ .../craftbukkit/help/SimpleHelpMap.java | 20 ++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/help/CommandAliasHelpTopic.java b/src/main/java/org/bukkit/craftbukkit/help/CommandAliasHelpTopic.java index 8830462fdb..4dcfef1cef 100644 --- a/src/main/java/org/bukkit/craftbukkit/help/CommandAliasHelpTopic.java +++ b/src/main/java/org/bukkit/craftbukkit/help/CommandAliasHelpTopic.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.help; +import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.help.HelpMap; @@ -14,6 +15,7 @@ public class CommandAliasHelpTopic extends HelpTopic { this.aliasFor = aliasFor.startsWith("/") ? aliasFor : "/" + aliasFor; this.helpMap = helpMap; 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; } diff --git a/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java b/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java index ec25c351e4..cdde69ce32 100644 --- a/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java +++ b/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java @@ -16,10 +16,10 @@ import java.util.*; * Standard implementation of {@link HelpMap} for CraftBukkit servers. */ public class SimpleHelpMap implements HelpMap { - + private final HelpTopic defaultTopic; private final Map helpTopics; - private final Set pluginIndexes; + private final Set pluginIndexes; private final Map> topicFactoryMap; private final CraftServer server; private HelpYamlReader yaml; @@ -40,7 +40,7 @@ public class SimpleHelpMap implements HelpMap { registerHelpTopicFactory(MultipleCommandAlias.class, new MultipleCommandAliasHelpTopicFactory()); } - + public synchronized HelpTopic getHelpTopic(String topicName) { if (topicName.equals("")) { return defaultTopic; @@ -112,14 +112,16 @@ public class SimpleHelpMap implements HelpMap { } addTopic(new GenericCommandHelpTopic(command)); } - + // Initialize command alias help topics for (Command command : server.getCommandMap().getCommands()) { if (commandInIgnoredPlugin(command, ignoredPlugins)) { continue; } 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 addTopic(new IndexHelpTopic("Aliases", "Lists command aliases", null, Collections2.filter(helpTopics.values(), Predicates.instanceOf(CommandAliasHelpTopic.class)))); - + // Initialize plugin-level sub-topics Map> pluginIndexes = new HashMap>(); fillPluginIndexes(pluginIndexes, server.getCommandMap().getCommands()); @@ -152,7 +154,7 @@ public class SimpleHelpMap implements HelpMap { } } } - + private void fillPluginIndexes(Map> pluginIndexes, Collection commands) { for (Command command : commands) { String pluginName = getCommandPluginName(command); @@ -167,7 +169,7 @@ public class SimpleHelpMap implements HelpMap { } } } - + private String getCommandPluginName(Command command) { if (command instanceof BukkitCommand || command instanceof VanillaCommand) { return "Bukkit"; @@ -177,7 +179,7 @@ public class SimpleHelpMap implements HelpMap { } return null; } - + private boolean commandInIgnoredPlugin(Command command, Set ignoredPlugins) { if ((command instanceof BukkitCommand || command instanceof VanillaCommand) && ignoredPlugins.contains("Bukkit")) { return true;