From 88103cefc2fd2e85c31d6c5bee979b5df0104889 Mon Sep 17 00:00:00 2001 From: StevenLawson Date: Wed, 28 Aug 2013 11:26:08 -0400 Subject: [PATCH] Some more tweaks to WebHelp. --- .../TotalFreedomMod/Commands/AdminLevel.java | 14 +++- .../Commands/TFM_CommandLoader.java | 53 +++++++++------ .../TotalFreedomMod/HTTPD/Module_help.java | 65 ++++++++++++++----- .../TotalFreedomMod/TFM_ProtectedArea.java | 1 + .../TotalFreedomMod/TFM_ServerInterface.java | 1 + .../TotalFreedomMod/TFM_Util.java | 2 +- 6 files changed, 97 insertions(+), 39 deletions(-) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/AdminLevel.java b/src/me/StevenLawson/TotalFreedomMod/Commands/AdminLevel.java index 48131c8..19c2976 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/AdminLevel.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/AdminLevel.java @@ -2,5 +2,17 @@ package me.StevenLawson.TotalFreedomMod.Commands; public enum AdminLevel { - ALL, OP, SUPER, SENIOR + ALL("All Player Commands"), OP("OP Commands"), SUPER("SuperAdmin Commands"), SENIOR("Senior Admin Commands"); + // + private final String friendlyName; + + private AdminLevel(String friendlyName) + { + this.friendlyName = friendlyName; + } + + public String getFriendlyName() + { + return friendlyName; + } } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java index ce8823e..ffa210d 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_CommandLoader.java @@ -46,21 +46,7 @@ public class TFM_CommandLoader for (TFM_CommandInfo commandInfo : commandList) { - String description = commandInfo.getDescription(); - switch (commandInfo.getLevel()) - { - case SENIOR: - description = "Senior " + (commandInfo.getSource() == SourceType.ONLY_CONSOLE ? "Console" : "") + " Command - " + description; - break; - case SUPER: - description = "Superadmin Command - " + description; - break; - case OP: - description = "OP Command - " + description; - break; - } - - TFM_DynamicCommand dynamicCommand = new TFM_DynamicCommand(commandInfo.getCommandName(), description, commandInfo.getUsage(), commandInfo.getAliases()); + TFM_DynamicCommand dynamicCommand = new TFM_DynamicCommand(commandInfo); Command existing = commandMap.getCommand(dynamicCommand.getName()); if (existing != null) @@ -191,7 +177,7 @@ public class TFM_CommandLoader return commandList; } - private static class TFM_CommandInfo + public static class TFM_CommandInfo { private final String commandName; private final Class commandClass; @@ -234,6 +220,26 @@ public class TFM_CommandLoader return description; } + public String getDescriptionPermissioned() + { + String _description = description; + + switch (this.getLevel()) + { + case SENIOR: + _description = "Senior " + (this.getSource() == SourceType.ONLY_CONSOLE ? "Console" : "") + " Command - " + _description; + break; + case SUPER: + _description = "Superadmin Command - " + _description; + break; + case OP: + _description = "OP Command - " + _description; + break; + } + + return _description; + } + public AdminLevel getLevel() { return level; @@ -270,11 +276,15 @@ public class TFM_CommandLoader } } - private class TFM_DynamicCommand extends Command implements PluginIdentifiableCommand + public class TFM_DynamicCommand extends Command implements PluginIdentifiableCommand { - public TFM_DynamicCommand(String commandName, String description, String usage, List aliases) + private final TFM_CommandInfo commandInfo; + + private TFM_DynamicCommand(TFM_CommandInfo commandInfo) { - super(commandName, description, usage, aliases); + super(commandInfo.getCommandName(), commandInfo.getDescriptionPermissioned(), commandInfo.getUsage(), commandInfo.getAliases()); + + this.commandInfo = commandInfo; } @Override @@ -312,6 +322,11 @@ public class TFM_CommandLoader { return TotalFreedomMod.plugin; } + + public TFM_CommandInfo getCommandInfo() + { + return commandInfo; + } } public static TFM_CommandLoader getInstance() diff --git a/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java b/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java index 16c4f15..ddd22f9 100644 --- a/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java +++ b/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_help.java @@ -7,14 +7,16 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import me.StevenLawson.TotalFreedomMod.Commands.AdminLevel; import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader; +import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader.TFM_DynamicCommand; import org.bukkit.command.Command; import org.bukkit.command.CommandMap; import org.bukkit.command.PluginIdentifiableCommand; +import org.apache.commons.lang3.StringUtils; import static me.StevenLawson.TotalFreedomMod.HTTPD.HTMLGenerationTools.*; import static org.apache.commons.lang3.StringEscapeUtils.*; -import org.apache.commons.lang3.StringUtils; public class Module_help extends TFM_HTTPD_Module { @@ -36,7 +38,11 @@ public class Module_help extends TFM_HTTPD_Module return paragraph("Error loading commands."); } - responseBody.append(heading("Command Help", 1)).append(paragraph("This page is an automatically generated listing of all plugin commands that are currently live on the server. Please note that it does not include vanilla server commands.")); + responseBody + .append(heading("Command Help", 1)) + .append(paragraph( + "This page is an automatically generated listing of all plugin commands that are currently live on the server. " + + "Please note that it does not include vanilla server commands.")); final Map> commandsByPlugin = new HashMap>(); @@ -74,31 +80,31 @@ public class Module_help extends TFM_HTTPD_Module @Override public int compare(Command a, Command b) { + if (a instanceof TFM_DynamicCommand && b instanceof TFM_DynamicCommand) + { + String aName = ((TFM_DynamicCommand) a).getCommandInfo().getLevel().name() + a.getName(); + String bName = ((TFM_DynamicCommand) b).getCommandInfo().getLevel().name() + b.getName(); + return aName.compareTo(bName); + } return a.getName().compareTo(b.getName()); } }); responseBody.append(heading(pluginName, 2)).append("
    \r\n"); + AdminLevel lastTfmCommandLevel = null; for (Command command : commands) { - responseBody - .append("
  • ") - .append(escapeHtml4(command.getName())) - .append(" - Usage: ") - .append(escapeHtml4(command.getUsage().replace("", command.getName()).trim())) - .append(""); - - if (!command.getAliases().isEmpty()) + if ("TotalFreedomMod".equals(pluginName)) { - responseBody.append(" - Aliases: ") - .append(escapeHtml4(StringUtils.join(command.getAliases(), ", "))) - .append(""); + AdminLevel tfmCommandLevel = ((TFM_DynamicCommand) command).getCommandInfo().getLevel(); + if (lastTfmCommandLevel == null || lastTfmCommandLevel != tfmCommandLevel) + { + responseBody.append("
\r\n").append(heading(tfmCommandLevel.getFriendlyName(), 3)).append("
    \r\n"); + } + lastTfmCommandLevel = tfmCommandLevel; } - - responseBody.append("
    ") - .append(escapeHtml4(command.getDescription())) - .append("\r\n"); + responseBody.append(buildDescription(command)); } responseBody.append("
\r\n"); @@ -107,10 +113,33 @@ public class Module_help extends TFM_HTTPD_Module return responseBody.toString(); } + private static String buildDescription(Command command) + { + StringBuilder sb = new StringBuilder(); + + sb.append( + "
  • {$CMD_NAME} - Usage: {$CMD_USAGE}" + .replace("{$CMD_NAME}", escapeHtml4(command.getName().trim())) + .replace("{$CMD_USAGE}", escapeHtml4(command.getUsage().trim()))); + + if (!command.getAliases().isEmpty()) + { + sb.append( + " - Aliases: {$CMD_ALIASES}" + .replace("{$CMD_ALIASES}", escapeHtml4(StringUtils.join(command.getAliases(), ", ")))); + } + + sb.append( + "
    {$CMD_DESC}
  • \r\n" + .replace("{$CMD_DESC}", escapeHtml4(command.getDescription().trim()))); + + return sb.toString(); + } + @Override public String getTitle() { - return "TotalFreedomMod :: WebHelp"; + return "TotalFreedomMod :: Command Help"; } @Override diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java b/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java index 83d859b..48096ef 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_ProtectedArea.java @@ -89,6 +89,7 @@ public class TFM_ProtectedArea implements Serializable } } + @SuppressWarnings("unchecked") public static void loadProtectedAreas() { try diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java b/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java index 3a2b014..562e0a0 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_ServerInterface.java @@ -48,6 +48,7 @@ public class TFM_ServerInterface nameBans.remove(name); } + @SuppressWarnings("unchecked") public static void banUsername(String name, String reason, String source, Date expireDate) { name = name.toLowerCase().trim(); diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index 0cc2c34..e200628 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -16,7 +16,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.exception.ExceptionUtils; import org.bukkit.*; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.block.Skull; import org.bukkit.command.CommandSender; import org.bukkit.entity.*; @@ -796,6 +795,7 @@ public class TFM_Util } } + @SuppressWarnings("unchecked") public static boolean isFromHostConsole(String senderName) { return ((List) TFM_ConfigEntry.HOST_SENDER_NAMES.getList()).contains(senderName.toLowerCase());