diff options
author | rmichela <deltahat@gmail.com> | 2012-03-16 00:41:13 -0400 |
---|---|---|
committer | EvilSeph <evilseph@gmail.com> | 2012-03-16 03:12:48 -0400 |
commit | 4589e943f6796f96a3cab0b1ea2563bc9a357b15 (patch) | |
tree | 8585f9057629c5b21694c1511a1fb102a66abd10 /src/main/java/org/bukkit | |
parent | 46429c6cb948f5338f253c1e22cce459704d773b (diff) | |
download | craftbukkit-4589e943f6796f96a3cab0b1ea2563bc9a357b15.tar craftbukkit-4589e943f6796f96a3cab0b1ea2563bc9a357b15.tar.gz craftbukkit-4589e943f6796f96a3cab0b1ea2563bc9a357b15.tar.lz craftbukkit-4589e943f6796f96a3cab0b1ea2563bc9a357b15.tar.xz craftbukkit-4589e943f6796f96a3cab0b1ea2563bc9a357b15.zip |
[Bleeding] Added support for color codes in help.yml. Addresses BUKKIT-1191
Diffstat (limited to 'src/main/java/org/bukkit')
3 files changed, 40 insertions, 20 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/help/HelpTopicComparator.java b/src/main/java/org/bukkit/craftbukkit/help/HelpTopicComparator.java index 9c0028ec..c88bfafb 100644 --- a/src/main/java/org/bukkit/craftbukkit/help/HelpTopicComparator.java +++ b/src/main/java/org/bukkit/craftbukkit/help/HelpTopicComparator.java @@ -9,17 +9,34 @@ import java.util.Comparator; * that start with a slash come after topics that don't. */ public class HelpTopicComparator implements Comparator<HelpTopic> { - private TopicNameComparator tnc = new TopicNameComparator(); + + // Singleton implementations + private static final TopicNameComparator tnc = new TopicNameComparator(); + public static TopicNameComparator topicNameComparatorInstance() { + return tnc; + } + + private static final HelpTopicComparator htc = new HelpTopicComparator(); + public static HelpTopicComparator helpTopicComparatorInstance() { + return htc; + } + + private HelpTopicComparator() {} public int compare(HelpTopic lhs, HelpTopic rhs) { return tnc.compare(lhs.getName(), rhs.getName()); } public static class TopicNameComparator implements Comparator<String> { + private TopicNameComparator(){} + public int compare(String lhs, String rhs) { - if (lhs.startsWith("/") && !rhs.startsWith("/")) { + boolean lhsStartSlash = lhs.startsWith("/"); + boolean rhsStartSlash = rhs.startsWith("/"); + + if (lhsStartSlash && !rhsStartSlash) { return 1; - } else if (!lhs.startsWith("/") && rhs.startsWith("/")) { + } else if (!lhsStartSlash && rhsStartSlash) { return -1; } else { return lhs.compareToIgnoreCase(rhs); diff --git a/src/main/java/org/bukkit/craftbukkit/help/HelpYamlReader.java b/src/main/java/org/bukkit/craftbukkit/help/HelpYamlReader.java index abef75e7..158a781c 100644 --- a/src/main/java/org/bukkit/craftbukkit/help/HelpYamlReader.java +++ b/src/main/java/org/bukkit/craftbukkit/help/HelpYamlReader.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.help; +import org.bukkit.ChatColor; import org.bukkit.Server; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -16,7 +17,8 @@ import java.util.logging.Level; */ public class HelpYamlReader { - private YamlConfiguration helpYaml; + private final YamlConfiguration helpYaml; + private final char ALT_COLOR_CODE = '&'; public HelpYamlReader(Server server) { File helpYamlFile = new File("help.yml"); @@ -43,8 +45,8 @@ public class HelpYamlReader { if (generalTopics != null) { for (String topicName : generalTopics.getKeys(false)) { ConfigurationSection section = generalTopics.getConfigurationSection(topicName); - String shortText = section.getString("shortText"); - String fullText = section.getString("fullText"); + String shortText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("shortText")); + String fullText = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("fullText")); String permission = section.getString("permission"); topics.add(new CustomHelpTopic(topicName, shortText, fullText, permission)); } @@ -62,8 +64,8 @@ public class HelpYamlReader { if (commandTopics != null) { for (String topicName : commandTopics.getKeys(false)) { ConfigurationSection section = commandTopics.getConfigurationSection(topicName); - String description = section.getString("shortText"); - String usage = section.getString("fullText"); + String description = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("shortText")); + String usage = ChatColor.translateAlternateColorCodes(ALT_COLOR_CODE, section.getString("fullText")); String permission = section.getString("permission"); amendments.add(new HelpTopicAmendment(topicName, description, usage, permission)); } diff --git a/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java b/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java index 1fc57a09..ec25c351 100644 --- a/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java +++ b/src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java @@ -10,7 +10,6 @@ import org.bukkit.command.defaults.VanillaCommand; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.help.*; -import javax.annotation.Nullable; import java.util.*; /** @@ -18,16 +17,16 @@ import java.util.*; */ public class SimpleHelpMap implements HelpMap { - private HelpTopic defaultTopic; - private Map<String, HelpTopic> helpTopics; - private Set<HelpTopic> pluginIndexes; - private Map<Class, HelpTopicFactory<Command>> topicFactoryMap; - private CraftServer server; + private final HelpTopic defaultTopic; + private final Map<String, HelpTopic> helpTopics; + private final Set<HelpTopic> pluginIndexes; + private final Map<Class, HelpTopicFactory<Command>> topicFactoryMap; + private final CraftServer server; private HelpYamlReader yaml; public SimpleHelpMap(CraftServer server) { - 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.helpTopics = new TreeMap<String, HelpTopic>(HelpTopicComparator.topicNameComparatorInstance()); // Using a TreeMap for its explicit sorting on key + this.pluginIndexes = new TreeSet<HelpTopic>(HelpTopicComparator.helpTopicComparatorInstance()); this.topicFactoryMap = new HashMap<Class, HelpTopicFactory<Command>>(); this.server = server; this.yaml = new HelpYamlReader(server); @@ -77,6 +76,8 @@ public class SimpleHelpMap implements HelpMap { * Reads the general topics from help.yml and adds them to the help index. */ public synchronized void initializeGeneralTopics() { + yaml = new HelpYamlReader(server); + // Initialize general help topics from the help.yml file for (HelpTopic topic : yaml.getGeneralTopics()) { addTopic(topic); @@ -88,7 +89,7 @@ public class SimpleHelpMap implements HelpMap { */ public synchronized void initializeCommands() { // ** Load topics from highest to lowest priority order ** - List<String> ignoredPlugins = yaml.getIgnoredPlugins(); + Set<String> ignoredPlugins = new HashSet<String>(yaml.getIgnoredPlugins()); // Initialize help topics from the server's command map outer: for (Command command : server.getCommandMap().getCommands()) { @@ -159,7 +160,7 @@ public class SimpleHelpMap implements HelpMap { HelpTopic topic = getHelpTopic("/" + command.getLabel()); if (topic != null) { if (!pluginIndexes.containsKey(pluginName)) { - pluginIndexes.put(pluginName, new TreeSet<HelpTopic>(new HelpTopicComparator())); //keep things in topic order + pluginIndexes.put(pluginName, new TreeSet<HelpTopic>(HelpTopicComparator.helpTopicComparatorInstance())); //keep things in topic order } pluginIndexes.get(pluginName).add(topic); } @@ -177,7 +178,7 @@ public class SimpleHelpMap implements HelpMap { return null; } - private boolean commandInIgnoredPlugin(Command command, List<String> ignoredPlugins) { + private boolean commandInIgnoredPlugin(Command command, Set<String> ignoredPlugins) { if ((command instanceof BukkitCommand || command instanceof VanillaCommand) && ignoredPlugins.contains("Bukkit")) { return true; } @@ -196,7 +197,7 @@ public class SimpleHelpMap implements HelpMap { private class IsCommandTopicPredicate implements Predicate<HelpTopic> { - public boolean apply(@Nullable HelpTopic topic) { + public boolean apply(HelpTopic topic) { return topic.getName().charAt(0) == '/'; } } |