geforkt von Mirrors/Paper
[Bleeding] Moved DefaultHelpTopic and GenericCommandHelpTopic to public bukkit api.
Dieser Commit ist enthalten in:
Ursprung
378424a1a1
Commit
03ce67c38c
@ -1,57 +0,0 @@
|
||||
package org.bukkit.craftbukkit.help;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.help.HelpTopic;
|
||||
import org.bukkit.util.ChatPaginator;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* This help topic generates the list of all other help topics.
|
||||
*/
|
||||
public class DefaultHelpTopic extends HelpTopic {
|
||||
|
||||
private Collection<HelpTopic> allTopics;
|
||||
|
||||
public DefaultHelpTopic(Collection<HelpTopic> allTopics) {
|
||||
this.allTopics = allTopics;
|
||||
}
|
||||
|
||||
public boolean canSee(CommandSender sender) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Overall";
|
||||
}
|
||||
|
||||
public String getShortText() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getFullText(CommandSender sender) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (HelpTopic topic : allTopics) {
|
||||
if (topic.canSee(sender)) {
|
||||
StringBuilder line = new StringBuilder();
|
||||
line.append(ChatColor.GOLD);
|
||||
line.append(topic.getName());
|
||||
line.append(": ");
|
||||
line.append(ChatColor.WHITE);
|
||||
line.append(topic.getShortText());
|
||||
|
||||
String lineStr = line.toString().replace("\n", ". ");
|
||||
if (sender instanceof Player && lineStr.length() > ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH) {
|
||||
sb.append(lineStr.substring(0, ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH - 3));
|
||||
sb.append("...");
|
||||
} else {
|
||||
sb.append(lineStr);
|
||||
}
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package org.bukkit.craftbukkit.help;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.defaults.VanillaCommand;
|
||||
import org.bukkit.help.HelpTopic;
|
||||
|
||||
public class GenericCommandHelpTopic extends HelpTopic {
|
||||
|
||||
private Command command;
|
||||
|
||||
public GenericCommandHelpTopic(Command command) {
|
||||
this.command = command;
|
||||
|
||||
if (command.getLabel().startsWith("/")) {
|
||||
name = command.getLabel();
|
||||
} else {
|
||||
name = "/" + command.getLabel();
|
||||
}
|
||||
|
||||
// The short text is the first line of the description
|
||||
int i = command.getDescription().indexOf("\n");
|
||||
if (i > 1) {
|
||||
shortText = command.getDescription().substring(0, i - 1);
|
||||
} else {
|
||||
shortText = command.getDescription();
|
||||
}
|
||||
|
||||
// Build full text
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
sb.append(ChatColor.GOLD);
|
||||
sb.append("Description: ");
|
||||
sb.append(ChatColor.WHITE);
|
||||
sb.append(command.getDescription());
|
||||
|
||||
sb.append("\n");
|
||||
|
||||
sb.append(ChatColor.GOLD);
|
||||
sb.append("Usage: ");
|
||||
sb.append(ChatColor.WHITE);
|
||||
sb.append(command.getUsage().replace("<command>", name.substring(1)));
|
||||
|
||||
if (command.getAliases().size() > 0) {
|
||||
sb.append("\n");
|
||||
sb.append(ChatColor.GOLD);
|
||||
sb.append("Aliases: ");
|
||||
sb.append(ChatColor.WHITE);
|
||||
sb.append(ChatColor.WHITE + StringUtils.join(command.getAliases(), ", "));
|
||||
}
|
||||
fullText = sb.toString();
|
||||
}
|
||||
|
||||
public boolean canSee(CommandSender sender) {
|
||||
if (!command.isRegistered() && !(command instanceof VanillaCommand)) {
|
||||
// Unregistered commands should not show up in the help (ignore VanillaCommands)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return command.testPermissionSilent(sender);
|
||||
}
|
||||
}
|
@ -6,9 +6,7 @@ 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;
|
||||
import org.bukkit.help.HelpTopic;
|
||||
import org.bukkit.help.HelpTopicFactory;
|
||||
import org.bukkit.help.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -23,7 +21,7 @@ public class SimpleHelpMap implements HelpMap {
|
||||
|
||||
public SimpleHelpMap() {
|
||||
helpTopics = new TreeMap<String, HelpTopic>(new HelpTopicComparator()); // Using a TreeMap for its explicit sorting on key
|
||||
defaultTopic = new DefaultHelpTopic(helpTopics.values());
|
||||
defaultTopic = new IndexHelpTopic(helpTopics.values());
|
||||
topicFactoryMap = new HashMap<Class, HelpTopicFactory>();
|
||||
|
||||
registerHelpTopicFactory(MultipleCommandAlias.class, new MultipleCommandAliasHelpTopicFactory());
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren