3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-06 03:20:06 +01:00

Improved command help format a bit

Dieser Commit ist enthalten in:
zml2008 2012-04-12 19:29:20 -07:00
Ursprung 3e77e024c0
Commit ff0f9073db
3 geänderte Dateien mit 45 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -61,7 +61,7 @@ public class CommandRegistration {
} }
for (CommandInfo command : registered) { for (CommandInfo command : registered) {
DynamicPluginCommand cmd = new DynamicPluginCommand(command.getAliases(), DynamicPluginCommand cmd = new DynamicPluginCommand(command.getAliases(),
command.getDesc(), "/" + command.getAliases()[0] + " " + command.getUsage(), executor, command.getRegisteredWith()); command.getDesc(), "/" + command.getAliases()[0] + " " + command.getUsage(), executor, command.getRegisteredWith(), plugin);
cmd.setPermissions(command.getPermissions()); cmd.setPermissions(command.getPermissions());
commandMap.register(plugin.getDescription().getName(), cmd); commandMap.register(plugin.getDescription().getName(), cmd);
} }
@ -93,7 +93,7 @@ public class CommandRegistration {
} }
for (Iterator<org.bukkit.command.Command> i = knownCommands.values().iterator(); i.hasNext();) { for (Iterator<org.bukkit.command.Command> i = knownCommands.values().iterator(); i.hasNext();) {
org.bukkit.command.Command cmd = i.next(); org.bukkit.command.Command cmd = i.next();
if (cmd instanceof DynamicPluginCommand && ((DynamicPluginCommand) cmd).getOwner().equals(plugin)) { if (cmd instanceof DynamicPluginCommand && ((DynamicPluginCommand) cmd).getOwner().equals(executor)) {
i.remove(); i.remove();
for (String alias : cmd.getAliases()) { for (String alias : cmd.getAliases()) {
org.bukkit.command.Command aliasCmd = knownCommands.get(alias); org.bukkit.command.Command aliasCmd = knownCommands.get(alias);

Datei anzeigen

@ -22,20 +22,25 @@ package com.sk89q.bukkit.util;
import com.sk89q.util.StringUtil; import com.sk89q.util.StringUtil;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.plugin.Plugin;
import java.util.Arrays; import java.util.Arrays;
/** /**
* @author zml2008 * @author zml2008
*/ */
public class DynamicPluginCommand extends org.bukkit.command.Command { public class DynamicPluginCommand extends org.bukkit.command.Command implements PluginIdentifiableCommand {
protected final CommandExecutor owner; protected final CommandExecutor owner;
protected final Object registeredWith; protected final Object registeredWith;
protected final Plugin owningPlugin;
protected String[] permissions = new String[0]; protected String[] permissions = new String[0];
public DynamicPluginCommand(String[] aliases, String desc, String usage, CommandExecutor owner, Object registeredWith) { public DynamicPluginCommand(String[] aliases, String desc, String usage, CommandExecutor owner, Object registeredWith, Plugin plugin) {
super(aliases[0], desc, usage, Arrays.asList(aliases)); super(aliases[0], desc, usage, Arrays.asList(aliases));
this.owner = owner; this.owner = owner;
this.owningPlugin = plugin;
this.registeredWith = registeredWith; this.registeredWith = registeredWith;
} }
@ -62,4 +67,9 @@ public class DynamicPluginCommand extends org.bukkit.command.Command {
public String[] getPermissions() { public String[] getPermissions() {
return permissions; return permissions;
} }
@Override
public Plugin getPlugin() {
return owningPlugin;
}
} }

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.bukkit.util;
import com.sk89q.minecraft.util.commands.CommandsManager; import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.wepif.PermissionsResolverManager; import com.sk89q.wepif.PermissionsResolverManager;
import com.sk89q.wepif.WEPIFRuntimeException; import com.sk89q.wepif.WEPIFRuntimeException;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.help.HelpTopic; import org.bukkit.help.HelpTopic;
@ -38,23 +39,49 @@ public class DynamicPluginCommandHelpTopic extends HelpTopic {
this.cmd = cmd; this.cmd = cmd;
this.name = "/" + cmd.getName(); this.name = "/" + cmd.getName();
String fullTextTemp = null;
StringBuilder fullText = new StringBuilder();
if (cmd.getRegisteredWith() instanceof CommandsManager) { if (cmd.getRegisteredWith() instanceof CommandsManager) {
Map<String, String> helpText = ((CommandsManager<?>) cmd.getRegisteredWith()).getHelpMessages(); Map<String, String> helpText = ((CommandsManager<?>) cmd.getRegisteredWith()).getHelpMessages();
final String lookupName = cmd.getName().replaceAll("/", ""); final String lookupName = cmd.getName().replaceAll("/", "");
if (helpText.containsKey(lookupName)) { if (helpText.containsKey(lookupName)) { // We have full help text for this command
this.fullText = helpText.get(lookupName); fullTextTemp = helpText.get(lookupName);
} }
// No full help text, assemble help text from info
helpText = ((CommandsManager<?>) cmd.getRegisteredWith()).getCommands(); helpText = ((CommandsManager<?>) cmd.getRegisteredWith()).getCommands();
if (helpText.containsKey(cmd.getName())) { if (helpText.containsKey(cmd.getName())) {
final String shortText = helpText.get(cmd.getName()); final String shortText = helpText.get(cmd.getName());
if (this.fullText == null) { if (fullTextTemp == null) {
this.fullText = this.name + " " + shortText; fullTextTemp = this.name + " " + shortText;
} }
this.shortText = shortText; this.shortText = shortText;
} }
} else { } else {
this.shortText = cmd.getDescription(); this.shortText = cmd.getDescription();
} }
// Put the usage in the format: Usage string (newline) Aliases (newline) Help text
String[] split = fullTextTemp == null ? new String[2] : fullTextTemp.split("\n", 2);
fullText.append(ChatColor.BOLD).append(ChatColor.GOLD).append("Usage: ").append(ChatColor.WHITE);
fullText.append(split[0]).append("\n");
if (cmd.getAliases().size() > 0) {
fullText.append(ChatColor.BOLD).append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.WHITE);
boolean first = true;
for (String alias : cmd.getAliases()) {
if (!first) {
fullText.append(", ");
}
fullText.append(alias);
first = false;
}
fullText.append("\n");
}
if (split.length > 1) {
fullText.append(split[1]);
}
this.fullText = fullText.toString();
} }
@Override @Override