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) {
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());
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();) {
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();
for (String alias : cmd.getAliases()) {
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 org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.plugin.Plugin;
import java.util.Arrays;
/**
* @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 Object registeredWith;
protected final Plugin owningPlugin;
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));
this.owner = owner;
this.owningPlugin = plugin;
this.registeredWith = registeredWith;
}
@ -62,4 +67,9 @@ public class DynamicPluginCommand extends org.bukkit.command.Command {
public String[] getPermissions() {
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.wepif.PermissionsResolverManager;
import com.sk89q.wepif.WEPIFRuntimeException;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.help.HelpTopic;
@ -38,23 +39,49 @@ public class DynamicPluginCommandHelpTopic extends HelpTopic {
this.cmd = cmd;
this.name = "/" + cmd.getName();
String fullTextTemp = null;
StringBuilder fullText = new StringBuilder();
if (cmd.getRegisteredWith() instanceof CommandsManager) {
Map<String, String> helpText = ((CommandsManager<?>) cmd.getRegisteredWith()).getHelpMessages();
final String lookupName = cmd.getName().replaceAll("/", "");
if (helpText.containsKey(lookupName)) {
this.fullText = helpText.get(lookupName);
if (helpText.containsKey(lookupName)) { // We have full help text for this command
fullTextTemp = helpText.get(lookupName);
}
// No full help text, assemble help text from info
helpText = ((CommandsManager<?>) cmd.getRegisteredWith()).getCommands();
if (helpText.containsKey(cmd.getName())) {
final String shortText = helpText.get(cmd.getName());
if (this.fullText == null) {
this.fullText = this.name + " " + shortText;
if (fullTextTemp == null) {
fullTextTemp = this.name + " " + shortText;
}
this.shortText = shortText;
}
} else {
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