diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/help/HelpYamlReader.java | 4 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java | 37 | ||||
-rw-r--r-- | src/main/resources/configurations/help.yml | 3 |
3 files changed, 32 insertions, 12 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/help/HelpYamlReader.java b/src/main/java/org/bukkit/craftbukkit/help/HelpYamlReader.java index 064833f1..abef75e7 100644 --- a/src/main/java/org/bukkit/craftbukkit/help/HelpYamlReader.java +++ b/src/main/java/org/bukkit/craftbukkit/help/HelpYamlReader.java @@ -74,4 +74,8 @@ public class HelpYamlReader { public List<String> getIgnoredPlugins() { return helpYaml.getStringList("ignore-plugins"); } + + public boolean commandTopicsInMasterIndex() { + return helpYaml.getBoolean("command-topics-in-master-index", true); + } } diff --git a/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java b/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java index d5696c84..1fc57a09 100644 --- a/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java +++ b/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java @@ -1,15 +1,16 @@ package org.bukkit.craftbukkit.help; +import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.Collections2; import org.bukkit.ChatColor; -import org.bukkit.Server; import org.bukkit.command.*; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.command.defaults.VanillaCommand; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.help.*; +import javax.annotation.Nullable; import java.util.*; /** @@ -22,13 +23,21 @@ public class SimpleHelpMap implements HelpMap { private Set<HelpTopic> pluginIndexes; private Map<Class, HelpTopicFactory<Command>> topicFactoryMap; private CraftServer server; + private HelpYamlReader yaml; public SimpleHelpMap(CraftServer server) { - helpTopics = new TreeMap<String, HelpTopic>(new HelpTopicComparator.TopicNameComparator()); // Using a TreeMap for its explicit sorting on key - pluginIndexes = new TreeSet<HelpTopic>(new HelpTopicComparator()); - defaultTopic = new IndexHelpTopic("Index", null, null, Collections2.filter(helpTopics.values(), Predicates.not(Predicates.instanceOf(CommandAliasHelpTopic.class)))); - topicFactoryMap = new HashMap<Class, HelpTopicFactory<Command>>(); + this.helpTopics = new TreeMap<String, HelpTopic>(new HelpTopicComparator.TopicNameComparator()); // Using a TreeMap for its explicit sorting on key + this.pluginIndexes = new TreeSet<HelpTopic>(new HelpTopicComparator()); + this.topicFactoryMap = new HashMap<Class, HelpTopicFactory<Command>>(); this.server = server; + this.yaml = new HelpYamlReader(server); + + Predicate indexFilter = Predicates.not(Predicates.instanceOf(CommandAliasHelpTopic.class)); + if (!yaml.commandTopicsInMasterIndex()) { + indexFilter = Predicates.and(indexFilter, Predicates.not(new IsCommandTopicPredicate())); + } + + this.defaultTopic = new IndexHelpTopic("Index", null, null, Collections2.filter(helpTopics.values(), indexFilter)); registerHelpTopicFactory(MultipleCommandAlias.class, new MultipleCommandAliasHelpTopicFactory()); } @@ -61,17 +70,15 @@ public class SimpleHelpMap implements HelpMap { } public List<String> getIgnoredPlugins() { - return new HelpYamlReader(server).getIgnoredPlugins(); + return yaml.getIgnoredPlugins(); } /** * Reads the general topics from help.yml and adds them to the help index. */ public synchronized void initializeGeneralTopics() { - HelpYamlReader reader = new HelpYamlReader(server); - // Initialize general help topics from the help.yml file - for (HelpTopic topic : reader.getGeneralTopics()) { + for (HelpTopic topic : yaml.getGeneralTopics()) { addTopic(topic); } } @@ -81,8 +88,7 @@ public class SimpleHelpMap implements HelpMap { */ public synchronized void initializeCommands() { // ** Load topics from highest to lowest priority order ** - HelpYamlReader helpYamlReader = new HelpYamlReader(server); - List<String> ignoredPlugins = helpYamlReader.getIgnoredPlugins(); + List<String> ignoredPlugins = yaml.getIgnoredPlugins(); // Initialize help topics from the server's command map outer: for (Command command : server.getCommandMap().getCommands()) { @@ -136,7 +142,7 @@ public class SimpleHelpMap implements HelpMap { } // Amend help topics from the help.yml file - for (HelpTopicAmendment amendment : helpYamlReader.getTopicAmendments()) { + for (HelpTopicAmendment amendment : yaml.getTopicAmendments()) { if (helpTopics.containsKey(amendment.getTopicName())) { helpTopics.get(amendment.getTopicName()).amendTopic(amendment.getShortText(), amendment.getFullText()); if (amendment.getPermission() != null) { @@ -187,4 +193,11 @@ public class SimpleHelpMap implements HelpMap { } topicFactoryMap.put(commandClass, factory); } + + private class IsCommandTopicPredicate implements Predicate<HelpTopic> { + + public boolean apply(@Nullable HelpTopic topic) { + return topic.getName().charAt(0) == '/'; + } + } } diff --git a/src/main/resources/configurations/help.yml b/src/main/resources/configurations/help.yml index 1a4ac9fc..5e6ed5b9 100644 --- a/src/main/resources/configurations/help.yml +++ b/src/main/resources/configurations/help.yml @@ -11,6 +11,9 @@ # Examples are given below. Color codes are allowed. When amending command topic, the string <text> will be replaced # with the existing value in the help topic. # -- +# Set this to true to list the individual command help topics in the master help. +# command-topics-in-master-index: true +# -- # Each general topic will show up as a separate topic in the help index along with all the plugin command topics. # general-topics: # rules: |