diff options
author | rmichela <deltahat@gmail.com> | 2012-03-09 01:17:45 -0500 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-03-10 17:55:44 -0500 |
commit | 378424a1a17b7c1e6f2a6b3395a5fc875729a4dd (patch) | |
tree | d36e25fa7accda9228d46c23e83b0da89ba06619 | |
parent | 5c757df673fa0baf0eca32ec69f6386e27815c93 (diff) | |
download | craftbukkit-378424a1a17b7c1e6f2a6b3395a5fc875729a4dd.tar craftbukkit-378424a1a17b7c1e6f2a6b3395a5fc875729a4dd.tar.gz craftbukkit-378424a1a17b7c1e6f2a6b3395a5fc875729a4dd.tar.lz craftbukkit-378424a1a17b7c1e6f2a6b3395a5fc875729a4dd.tar.xz craftbukkit-378424a1a17b7c1e6f2a6b3395a5fc875729a4dd.zip |
[Bleeding] Added support for linking custom CommandExecutor types to a HelpTopicFactory. Fixes BUKKIT-1027
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java b/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java index a8424aab..b4843a94 100644 --- a/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java +++ b/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java @@ -1,7 +1,9 @@ package org.bukkit.craftbukkit.help; import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.MultipleCommandAlias; +import org.bukkit.command.PluginCommand; import org.bukkit.command.defaults.VanillaCommand; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.help.HelpMap; @@ -71,12 +73,18 @@ public class SimpleHelpMap implements HelpMap { // ** Load topics from highest to lowest priority order ** // Initialize help topics from the server's command map - for (Command command : server.getCommandMap().getCommands()) { - if (topicFactoryMap.containsKey(command.getClass())) { - addTopic(topicFactoryMap.get(command.getClass()).createTopic(command)); - } else { - addTopic(new GenericCommandHelpTopic(command)); + outer: for (Command command : server.getCommandMap().getCommands()) { + for (Class c : topicFactoryMap.keySet()) { + if (c.isAssignableFrom(command.getClass())) { + addTopic(topicFactoryMap.get(c).createTopic(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 @@ -94,8 +102,8 @@ public class SimpleHelpMap implements HelpMap { } public void registerHelpTopicFactory(Class commandClass, HelpTopicFactory factory) { - if (!Command.class.isAssignableFrom(commandClass)) { - throw new IllegalArgumentException("commandClass must implement Command"); + if (!Command.class.isAssignableFrom(commandClass) && !CommandExecutor.class.isAssignableFrom(commandClass)) { + throw new IllegalArgumentException("commandClass must implement either Command or CommandExecutor!"); } topicFactoryMap.put(commandClass, factory); } |