summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorrmichela <deltahat@gmail.com>2012-03-16 00:41:13 -0400
committerEvilSeph <evilseph@gmail.com>2012-03-16 03:12:48 -0400
commit4589e943f6796f96a3cab0b1ea2563bc9a357b15 (patch)
tree8585f9057629c5b21694c1511a1fb102a66abd10 /src/main
parent46429c6cb948f5338f253c1e22cce459704d773b (diff)
downloadcraftbukkit-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')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/help/HelpTopicComparator.java23
-rw-r--r--src/main/java/org/bukkit/craftbukkit/help/HelpYamlReader.java12
-rw-r--r--src/main/java/org/bukkit/craftbukkit/help/SimpleHelpMap.java25
-rw-r--r--src/main/resources/configurations/help.yml23
4 files changed, 52 insertions, 31 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) == '/';
}
}
diff --git a/src/main/resources/configurations/help.yml b/src/main/resources/configurations/help.yml
index 5e6ed5b9..d7f363b1 100644
--- a/src/main/resources/configurations/help.yml
+++ b/src/main/resources/configurations/help.yml
@@ -1,36 +1,37 @@
# This is the help configuration file for Bukkit.
+#
# By default you do not need to modify this file. Help topics for all plugin commands are automatically provided by
# or extracted from your installed plugins. You only need to modify this file if you wish to add new help pages to
# your server or override the help pages of existing plugin commands.
-# --
+#
# This file is divided up into the following parts:
# -- general-topics: lists admin defined topics
# -- amend-topics: lists topic amendments to apply to existing help topics
# -- ignore-plugins: lists any plugins that should be excluded from help
-# general-topics and command-topics respectively.
-# 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.
-# --
+#
+# Examples are given below. When amending command topic, the string <text> will be replaced with the existing value
+# in the help topic. Color codes can be used in topic text. The color code character is & followed by 0-F.
+#
# 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:
# shortText: Rules of the server
# fullText: |
-# 1. Be kind to your fellow players.
-# 2. No griefing.
-# 3. No swearing.
+# &61. Be kind to your fellow players.
+# &B2. No griefing.
+# &D3. No swearing.
# permission: topics.rules
-# --
+#
# Topic amendments are used to change the content of automatically generated plugin command topics.
# amended-topics:
# /stop:
# shortText: Stops the server cold....in its tracks!
# fullText: <text> - This kills the server.
# permission: you.dont.have
-# --
+#
# Any plugin in the ignored plugins list will be excluded from help. The name must match the name displayed by
# the /plugins command. Ignore "Bukkit" to remove the standard bukkit commands from the index.
# ignore-plugins: