3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-17 05:20:05 +01:00

[Bleeding] Added support for amending help topic visibility permissions in help.yml. Addresses BUKKIT-1113

Dieser Commit ist enthalten in:
rmichela 2012-03-10 18:08:12 -05:00 committet von EvilSeph
Ursprung a8b2c6d04e
Commit 996832ff6c
6 geänderte Dateien mit 45 neuen und 24 gelöschten Zeilen

Datei anzeigen

@ -1,7 +1,6 @@
package org.bukkit.craftbukkit.help; package org.bukkit.craftbukkit.help;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.help.HelpMap; import org.bukkit.help.HelpMap;
import org.bukkit.help.HelpTopic; import org.bukkit.help.HelpTopic;
@ -9,13 +8,11 @@ import org.bukkit.help.HelpTopic;
public class CommandAliasHelpTopic extends HelpTopic { public class CommandAliasHelpTopic extends HelpTopic {
private String aliasFor; private String aliasFor;
private Command command;
private HelpMap helpMap; private HelpMap helpMap;
public CommandAliasHelpTopic(String alias, String aliasFor, Command command, HelpMap helpMap) { public CommandAliasHelpTopic(String alias, String aliasFor, HelpMap helpMap) {
this.aliasFor = aliasFor.startsWith("/") ? aliasFor : "/" + aliasFor; this.aliasFor = aliasFor.startsWith("/") ? aliasFor : "/" + aliasFor;
this.helpMap = helpMap; this.helpMap = helpMap;
this.command = command;
this.name = alias.startsWith("/") ? alias : "/" + alias; this.name = alias.startsWith("/") ? alias : "/" + alias;
this.shortText = ChatColor.YELLOW + "Alias for " + ChatColor.WHITE + this.aliasFor; this.shortText = ChatColor.YELLOW + "Alias for " + ChatColor.WHITE + this.aliasFor;
} }
@ -33,11 +30,15 @@ public class CommandAliasHelpTopic extends HelpTopic {
@Override @Override
public boolean canSee(CommandSender commandSender) { public boolean canSee(CommandSender commandSender) {
HelpTopic aliasForTopic = helpMap.getHelpTopic(aliasFor); if (amendedPermission == null) {
if (aliasForTopic != null) { HelpTopic aliasForTopic = helpMap.getHelpTopic(aliasFor);
return aliasForTopic.canSee(commandSender); if (aliasForTopic != null) {
return aliasForTopic.canSee(commandSender);
} else {
return false;
}
} else { } else {
return false; return commandSender.hasPermission(amendedPermission);
} }
} }
} }

Datei anzeigen

@ -7,11 +7,13 @@ public class HelpTopicAmendment {
private String topicName; private String topicName;
private String shortText; private String shortText;
private String fullText; private String fullText;
private String permission;
public HelpTopicAmendment(String topicName, String shortText, String fullText) { public HelpTopicAmendment(String topicName, String shortText, String fullText, String permission) {
this.fullText = fullText; this.fullText = fullText;
this.shortText = shortText; this.shortText = shortText;
this.topicName = topicName; this.topicName = topicName;
this.permission = permission;
} }
/** /**
@ -37,4 +39,12 @@ public class HelpTopicAmendment {
public String getTopicName() { public String getTopicName() {
return topicName; return topicName;
} }
/**
* Gets the amended permission
* @return the permission
*/
public String getPermission() {
return permission;
}
} }

Datei anzeigen

@ -64,7 +64,8 @@ public class HelpYamlReader {
ConfigurationSection section = commandTopics.getConfigurationSection(topicName); ConfigurationSection section = commandTopics.getConfigurationSection(topicName);
String description = section.getString("shortText"); String description = section.getString("shortText");
String usage = section.getString("fullText"); String usage = section.getString("fullText");
amendments.add(new HelpTopicAmendment(topicName, description, usage)); String permission = section.getString("permission");
amendments.add(new HelpTopicAmendment(topicName, description, usage, permission));
} }
} }
return amendments; return amendments;

Datei anzeigen

@ -35,16 +35,20 @@ public class MultipleCommandAliasHelpTopic extends HelpTopic {
} }
public boolean canSee(CommandSender sender) { public boolean canSee(CommandSender sender) {
if (sender instanceof ConsoleCommandSender) { if (amendedPermission == null) {
return true; if (sender instanceof ConsoleCommandSender) {
} return true;
for (Command command : alias.getCommands()) {
if (!command.testPermissionSilent(sender)) {
return false;
} }
}
return true; for (Command command : alias.getCommands()) {
if (!command.testPermissionSilent(sender)) {
return false;
}
}
return true;
} else {
return sender.hasPermission(amendedPermission);
}
} }
} }

Datei anzeigen

@ -69,6 +69,7 @@ public class SimpleHelpMap implements HelpMap {
* Processes all the commands registered in the server and creates help topics for them. * Processes all the commands registered in the server and creates help topics for them.
* @param server A reference to the server. * @param server A reference to the server.
*/ */
@SuppressWarnings("unchecked")
public synchronized void initializeCommands(CraftServer server) { public synchronized void initializeCommands(CraftServer server) {
// ** Load topics from highest to lowest priority order ** // ** Load topics from highest to lowest priority order **
@ -90,7 +91,7 @@ public class SimpleHelpMap implements HelpMap {
// Initialize command alias help topics // Initialize command alias help topics
for (Command command : server.getCommandMap().getCommands()) { for (Command command : server.getCommandMap().getCommands()) {
for (String alias : command.getAliases()) { for (String alias : command.getAliases()) {
addTopic(new CommandAliasHelpTopic(alias, command.getLabel(), command, this)); addTopic(new CommandAliasHelpTopic(alias, command.getLabel(), this));
} }
} }
@ -99,16 +100,19 @@ public class SimpleHelpMap implements HelpMap {
addTopic(new GenericCommandHelpTopic(command)); addTopic(new GenericCommandHelpTopic(command));
} }
// Add alias sub-index
addTopic(new IndexHelpTopic("Aliases", "Lists command aliases", null, Collections2.filter(helpTopics.values(), Predicates.instanceOf(CommandAliasHelpTopic.class))));
// Amend help topics from the help.yml file // Amend help topics from the help.yml file
HelpYamlReader reader = new HelpYamlReader(server); HelpYamlReader reader = new HelpYamlReader(server);
for (HelpTopicAmendment amendment : reader.getTopicAmendments()) { for (HelpTopicAmendment amendment : reader.getTopicAmendments()) {
if (helpTopics.containsKey(amendment.getTopicName())) { if (helpTopics.containsKey(amendment.getTopicName())) {
helpTopics.get(amendment.getTopicName()).amendTopic(amendment.getShortText(), amendment.getFullText()); helpTopics.get(amendment.getTopicName()).amendTopic(amendment.getShortText(), amendment.getFullText());
if (amendment.getPermission() != null) {
helpTopics.get(amendment.getTopicName()).amendCanSee(amendment.getPermission());
}
} }
} }
// 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) {

Datei anzeigen

@ -20,3 +20,4 @@
# /stop: # /stop:
# shortText: Stops the server cold....in its tracks! # shortText: Stops the server cold....in its tracks!
# fullText: <text> - This kills the server. # fullText: <text> - This kills the server.
# permission: you.dont.have