3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00

[Bleeding] Added support for color codes in help.yml. Addresses BUKKIT-1191

Dieser Commit ist enthalten in:
rmichela 2012-03-16 00:41:13 -04:00 committet von EvilSeph
Ursprung 46429c6cb9
Commit 4589e943f6
4 geänderte Dateien mit 52 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -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);

Datei anzeigen

@ -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));
}

Datei anzeigen

@ -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) == '/';
}
}

Datei anzeigen

@ -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: