[Bleeding] Added support for linking custom CommandExecutor types to a HelpTopicFactory. Fixes BUKKIT-1027

This commit is contained in:
rmichela 2012-03-09 01:17:45 -05:00 committed by EvilSeph
parent 5c757df673
commit 378424a1a1

View File

@ -1,7 +1,9 @@
package org.bukkit.craftbukkit.help; package org.bukkit.craftbukkit.help;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.MultipleCommandAlias; import org.bukkit.command.MultipleCommandAlias;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.defaults.VanillaCommand; import org.bukkit.command.defaults.VanillaCommand;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.help.HelpMap; import org.bukkit.help.HelpMap;
@ -71,12 +73,18 @@ public class SimpleHelpMap implements HelpMap {
// ** Load topics from highest to lowest priority order ** // ** Load topics from highest to lowest priority order **
// Initialize help topics from the server's command map // Initialize help topics from the server's command map
for (Command command : server.getCommandMap().getCommands()) { outer: for (Command command : server.getCommandMap().getCommands()) {
if (topicFactoryMap.containsKey(command.getClass())) { for (Class c : topicFactoryMap.keySet()) {
addTopic(topicFactoryMap.get(command.getClass()).createTopic(command)); if (c.isAssignableFrom(command.getClass())) {
} else { addTopic(topicFactoryMap.get(c).createTopic(command));
addTopic(new GenericCommandHelpTopic(command)); continue outer;
} }
if (command instanceof PluginCommand && c.isAssignableFrom(((PluginCommand)command).getExecutor().getClass())) {
addTopic(topicFactoryMap.get(c).createTopic(command));
continue outer;
}
}
addTopic(new GenericCommandHelpTopic(command));
} }
// Initialize help topics from the server's fallback commands // Initialize help topics from the server's fallback commands
@ -94,8 +102,8 @@ public class SimpleHelpMap implements HelpMap {
} }
public void registerHelpTopicFactory(Class commandClass, HelpTopicFactory factory) { public void registerHelpTopicFactory(Class commandClass, HelpTopicFactory factory) {
if (!Command.class.isAssignableFrom(commandClass)) { if (!Command.class.isAssignableFrom(commandClass) && !CommandExecutor.class.isAssignableFrom(commandClass)) {
throw new IllegalArgumentException("commandClass must implement Command"); throw new IllegalArgumentException("commandClass must implement either Command or CommandExecutor!");
} }
topicFactoryMap.put(commandClass, factory); topicFactoryMap.put(commandClass, factory);
} }