geforkt von Mirrors/Paper
[Bleeding] Implemented command aliases in help. Addresses BUKKIT-1028
Dieser Commit ist enthalten in:
Ursprung
03ce67c38c
Commit
a8b2c6d04e
43
src/main/java/org/bukkit/craftbukkit/help/CommandAliasHelpTopic.java
Normale Datei
43
src/main/java/org/bukkit/craftbukkit/help/CommandAliasHelpTopic.java
Normale Datei
@ -0,0 +1,43 @@
|
|||||||
|
package org.bukkit.craftbukkit.help;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.help.HelpMap;
|
||||||
|
import org.bukkit.help.HelpTopic;
|
||||||
|
|
||||||
|
public class CommandAliasHelpTopic extends HelpTopic {
|
||||||
|
|
||||||
|
private String aliasFor;
|
||||||
|
private Command command;
|
||||||
|
private HelpMap helpMap;
|
||||||
|
|
||||||
|
public CommandAliasHelpTopic(String alias, String aliasFor, Command command, HelpMap helpMap) {
|
||||||
|
this.aliasFor = aliasFor.startsWith("/") ? aliasFor : "/" + aliasFor;
|
||||||
|
this.helpMap = helpMap;
|
||||||
|
this.command = command;
|
||||||
|
this.name = alias.startsWith("/") ? alias : "/" + alias;
|
||||||
|
this.shortText = ChatColor.YELLOW + "Alias for " + ChatColor.WHITE + this.aliasFor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFullText(CommandSender forWho) {
|
||||||
|
StringBuilder sb = new StringBuilder(shortText);
|
||||||
|
HelpTopic aliasForTopic = helpMap.getHelpTopic(aliasFor);
|
||||||
|
if (aliasForTopic != null) {
|
||||||
|
sb.append("\n");
|
||||||
|
sb.append(aliasForTopic.getFullText(forWho));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canSee(CommandSender commandSender) {
|
||||||
|
HelpTopic aliasForTopic = helpMap.getHelpTopic(aliasFor);
|
||||||
|
if (aliasForTopic != null) {
|
||||||
|
return aliasForTopic.canSee(commandSender);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package org.bukkit.craftbukkit.help;
|
package org.bukkit.craftbukkit.help;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
|
import com.google.common.collect.Collections2;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.MultipleCommandAlias;
|
import org.bukkit.command.MultipleCommandAlias;
|
||||||
@ -21,7 +23,7 @@ public class SimpleHelpMap implements HelpMap {
|
|||||||
|
|
||||||
public SimpleHelpMap() {
|
public SimpleHelpMap() {
|
||||||
helpTopics = new TreeMap<String, HelpTopic>(new HelpTopicComparator()); // Using a TreeMap for its explicit sorting on key
|
helpTopics = new TreeMap<String, HelpTopic>(new HelpTopicComparator()); // Using a TreeMap for its explicit sorting on key
|
||||||
defaultTopic = new IndexHelpTopic(helpTopics.values());
|
defaultTopic = new IndexHelpTopic(null, null, null, Collections2.filter(helpTopics.values(), Predicates.not(Predicates.instanceOf(CommandAliasHelpTopic.class))));
|
||||||
topicFactoryMap = new HashMap<Class, HelpTopicFactory>();
|
topicFactoryMap = new HashMap<Class, HelpTopicFactory>();
|
||||||
|
|
||||||
registerHelpTopicFactory(MultipleCommandAlias.class, new MultipleCommandAliasHelpTopicFactory());
|
registerHelpTopicFactory(MultipleCommandAlias.class, new MultipleCommandAliasHelpTopicFactory());
|
||||||
@ -84,6 +86,13 @@ public class SimpleHelpMap implements HelpMap {
|
|||||||
}
|
}
|
||||||
addTopic(new GenericCommandHelpTopic(command));
|
addTopic(new GenericCommandHelpTopic(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize command alias help topics
|
||||||
|
for (Command command : server.getCommandMap().getCommands()) {
|
||||||
|
for (String alias : command.getAliases()) {
|
||||||
|
addTopic(new CommandAliasHelpTopic(alias, command.getLabel(), command, this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize help topics from the server's fallback commands
|
// Initialize help topics from the server's fallback commands
|
||||||
for (VanillaCommand command : server.getCommandMap().getFallbackCommands()) {
|
for (VanillaCommand command : server.getCommandMap().getFallbackCommands()) {
|
||||||
@ -97,6 +106,9 @@ public class SimpleHelpMap implements HelpMap {
|
|||||||
helpTopics.get(amendment.getTopicName()).amendTopic(amendment.getShortText(), amendment.getFullText());
|
helpTopics.get(amendment.getTopicName()).amendTopic(amendment.getShortText(), amendment.getFullText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add alias sub-index
|
||||||
|
addTopic(new IndexHelpTopic("Aliases", "Lists command aliases", null, Collections2.filter(helpTopics.values(), Predicates.instanceOf(CommandAliasHelpTopic.class))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerHelpTopicFactory(Class commandClass, HelpTopicFactory factory) {
|
public void registerHelpTopicFactory(Class commandClass, HelpTopicFactory factory) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren