From 0de7e2240888c6c861f3c24c0c04aea8a4874e05 Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 5 Feb 2013 08:50:47 -0500 Subject: [PATCH] Adjust how we get the usage strings for the /skillname commands --- .../commands/CommandRegistrationHelper.java | 2 + .../gmail/nossr50/skills/SkillCommand.java | 4 +- .../com/gmail/nossr50/skills/SkillGuide.java | 65 +++++++++++-------- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java b/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java index 639cbbcf8..4b644655e 100644 --- a/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java +++ b/src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java @@ -59,6 +59,8 @@ public final class CommandRegistrationHelper { command.setDescription(LocaleLoader.getString("Commands.Description.Skill", Misc.getCapitalized(localizedName))); command.setPermission("mcmmo.commands." + commandName); command.setPermissionMessage(permissionsMessage); + command.setUsage(LocaleLoader.getString("Commands.Usage.0", localizedName)); + command.setUsage(command.getUsage() + "\n" + LocaleLoader.getString("Commands.Usage.2", localizedName, "?", "[" + LocaleLoader.getString("Commands.Usage.Page") + "]")); switch (skill) { case ACROBATICS: diff --git a/src/main/java/com/gmail/nossr50/skills/SkillCommand.java b/src/main/java/com/gmail/nossr50/skills/SkillCommand.java index 1b9e8716e..88602ba2d 100644 --- a/src/main/java/com/gmail/nossr50/skills/SkillCommand.java +++ b/src/main/java/com/gmail/nossr50/skills/SkillCommand.java @@ -74,9 +74,7 @@ public abstract class SkillCommand implements CommandExecutor { statsDisplay(); - SkillGuide.grabGuidePageForSkill(skill, player, args); - - return true; + return SkillGuide.grabGuidePageForSkill(skill, player, args); } protected String calculateRank(int maxLevel, int rankChangeLevel) { diff --git a/src/main/java/com/gmail/nossr50/skills/SkillGuide.java b/src/main/java/com/gmail/nossr50/skills/SkillGuide.java index 94263ba84..99d65c26b 100644 --- a/src/main/java/com/gmail/nossr50/skills/SkillGuide.java +++ b/src/main/java/com/gmail/nossr50/skills/SkillGuide.java @@ -55,44 +55,55 @@ public final class SkillGuide { } } - public static void grabGuidePageForSkill(SkillType skilltype, Player player, String[] args) { + public static boolean grabGuidePageForSkill(SkillType skilltype, Player player, String[] args) { String skillName = skilltype.toString(); String capitalized = Misc.getCapitalized(skillName); String localized = SkillTools.localizeSkillName(skilltype); player.sendMessage(LocaleLoader.getString("Guides.Available", localized, localized.toLowerCase())); - if (args.length >= 1 && args[0].equals("?")) { - String address = "Guides." + capitalized; + String address = "Guides." + capitalized; + + switch (args.length) { + case 0: + // We have to specify this, otherwise we get the usage string every time we call /skillname... + return true; + + case 1: + if (!args[0].equals("?")) { + return false; + } + + SkillGuide.clearChat(player); + + for (String target : SkillGuide.grabPageContents(localized, address, 1)) { + player.sendMessage(target); + } + + return true; + + case 2: int totalPages = SkillGuide.getTotalPageNumber(address); - if (args.length == 1) { - SkillGuide.clearChat(player); - - for (String target : SkillGuide.grabPageContents(localized, address, 1)) { - player.sendMessage(target); - } + if (!Misc.isInt(args[1])) { + player.sendMessage(LocaleLoader.getString("Guides.Page.Invalid")); + return true; } - else { - if (!Misc.isInt(args[1])) { - player.sendMessage(LocaleLoader.getString("Guides.Page.Invalid")); - } - if (Misc.getInt(args[1]) <= totalPages) { - SkillGuide.clearChat(player); - - for (String target : SkillGuide.grabPageContents(localized, address, Misc.getInt(args[1]))) { - player.sendMessage(target); - } - } - else { - player.sendMessage(LocaleLoader.getString("Guides.Page.OutOfRange", totalPages)); - } + if (Misc.getInt(args[1]) > totalPages) { + player.sendMessage(LocaleLoader.getString("Guides.Page.OutOfRange", totalPages)); + return true; } - } - // We have to specify this, else we get the usage string every time we call /skillname... - else if (args.length != 0) { - player.sendMessage(LocaleLoader.getString("Guides.Usage", localized.toLowerCase())); + SkillGuide.clearChat(player); + + for (String target : SkillGuide.grabPageContents(localized, address, Misc.getInt(args[1]))) { + player.sendMessage(target); + } + + return true; + + default: + return false; } } } \ No newline at end of file