From 94d55c3be7f6a66b9a6103ab245988efad77187b Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Tue, 16 Jul 2024 11:03:13 -0400 Subject: [PATCH] Argument check and debug cleanup --- .../subcommands/BukkitQuestadminFinishCommand.java | 2 +- .../subcommands/BukkitQuestadminGiveCommand.java | 2 +- .../subcommands/BukkitQuestadminGivepointsCommand.java | 2 +- .../subcommands/BukkitQuestadminNextstageCommand.java | 3 ++- .../subcommands/BukkitQuestadminPointsCommand.java | 2 +- .../subcommands/BukkitQuestadminQuitCommand.java | 2 +- .../subcommands/BukkitQuestadminRemoveCommand.java | 2 +- .../subcommands/BukkitQuestadminSetstageCommand.java | 2 +- .../subcommands/BukkitQuestadminTakepointsCommand.java | 2 +- .../main/java/me/pikamug/quests/player/BukkitQuester.java | 7 +++---- .../implementation/file/BukkitQuestYamlStorage.java | 3 +-- core/src/main/java/me/pikamug/quests/util/BukkitLang.java | 6 +++--- 12 files changed, 17 insertions(+), 18 deletions(-) diff --git a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminFinishCommand.java b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminFinishCommand.java index cf60a9a6b..fe46fa223 100644 --- a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminFinishCommand.java +++ b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminFinishCommand.java @@ -67,7 +67,7 @@ public class BukkitQuestadminFinishCommand extends BukkitQuestsSubCommand { @Override public void execute(CommandSender cs, String[] args) { - if (args.length == 1) { + if (args.length < 3) { // Shows command usage return; } diff --git a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminGiveCommand.java b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminGiveCommand.java index bda297b7b..bba600c90 100644 --- a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminGiveCommand.java +++ b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminGiveCommand.java @@ -66,7 +66,7 @@ public class BukkitQuestadminGiveCommand extends BukkitQuestsSubCommand { @Override public void execute(CommandSender cs, String[] args) { - if (args.length == 1) { + if (args.length < 3) { // Shows command usage return; } diff --git a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminGivepointsCommand.java b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminGivepointsCommand.java index 140eb99d9..2521c8dce 100644 --- a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminGivepointsCommand.java +++ b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminGivepointsCommand.java @@ -64,7 +64,7 @@ public class BukkitQuestadminGivepointsCommand extends BukkitQuestsSubCommand { @Override public void execute(CommandSender cs, String[] args) { - if (args.length == 1) { + if (args.length < 3) { // Shows command usage return; } diff --git a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminNextstageCommand.java b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminNextstageCommand.java index cea4345d6..a1a1f6c03 100644 --- a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminNextstageCommand.java +++ b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminNextstageCommand.java @@ -67,7 +67,8 @@ public class BukkitQuestadminNextstageCommand extends BukkitQuestsSubCommand { @Override public void execute(CommandSender cs, String[] args) { - if (args.length == 1) { + if (args.length < 3) { + System.out.println(args.length); // Shows command usage return; } diff --git a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminPointsCommand.java b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminPointsCommand.java index d6a48e8be..a4a164cee 100644 --- a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminPointsCommand.java +++ b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminPointsCommand.java @@ -64,7 +64,7 @@ public class BukkitQuestadminPointsCommand extends BukkitQuestsSubCommand { @Override public void execute(CommandSender cs, String[] args) { - if (args.length == 1) { + if (args.length < 3) { // Shows command usage return; } diff --git a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminQuitCommand.java b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminQuitCommand.java index 1ee51b3ee..95fbae94b 100644 --- a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminQuitCommand.java +++ b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminQuitCommand.java @@ -67,7 +67,7 @@ public class BukkitQuestadminQuitCommand extends BukkitQuestsSubCommand { @Override public void execute(CommandSender cs, String[] args) { - if (args.length == 1) { + if (args.length < 3) { // Shows command usage return; } diff --git a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminRemoveCommand.java b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminRemoveCommand.java index b5e9e04cb..58ef7106b 100644 --- a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminRemoveCommand.java +++ b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminRemoveCommand.java @@ -67,7 +67,7 @@ public class BukkitQuestadminRemoveCommand extends BukkitQuestsSubCommand { @Override public void execute(CommandSender cs, String[] args) { - if (args.length == 1) { + if (args.length < 3) { // Shows command usage return; } diff --git a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminSetstageCommand.java b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminSetstageCommand.java index b830ff2bb..af876fb5e 100644 --- a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminSetstageCommand.java +++ b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminSetstageCommand.java @@ -67,7 +67,7 @@ public class BukkitQuestadminSetstageCommand extends BukkitQuestsSubCommand { @Override public void execute(CommandSender cs, String[] args) { - if (args.length == 1) { + if (args.length < 4) { // Shows command usage return; } diff --git a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminTakepointsCommand.java b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminTakepointsCommand.java index 628ec8b3e..85d817227 100644 --- a/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminTakepointsCommand.java +++ b/core/src/main/java/me/pikamug/quests/commands/questadmin/subcommands/BukkitQuestadminTakepointsCommand.java @@ -64,7 +64,7 @@ public class BukkitQuestadminTakepointsCommand extends BukkitQuestsSubCommand { @Override public void execute(CommandSender cs, String[] args) { - if (args.length == 1) { + if (args.length < 3) { // Shows command usage return; } diff --git a/core/src/main/java/me/pikamug/quests/player/BukkitQuester.java b/core/src/main/java/me/pikamug/quests/player/BukkitQuester.java index 904a088f4..9ac181841 100644 --- a/core/src/main/java/me/pikamug/quests/player/BukkitQuester.java +++ b/core/src/main/java/me/pikamug/quests/player/BukkitQuester.java @@ -3191,7 +3191,6 @@ public class BukkitQuester implements Quester { String message = formatCompletedObjectiveMessage("craftItem", goal.getAmount()); if (plugin.getConfigSettings().canTranslateNames() && !goal.hasItemMeta() && !goal.getItemMeta().hasDisplayName()) { - plugin.getLogger().info(goal.getType().name()); // Bukkit version is 1.9+ if (goal.getType().name().equals("TIPPED_ARROW")) { final String level = BukkitItemUtil.getPrettyPotionLevel(goal.getItemMeta()); @@ -3324,8 +3323,8 @@ public class BukkitQuester implements Quester { final String message = formatCompletedObjectiveMessage("killPlayer", goal.getAmount()); sendMessage(message); } else if (type.equals(ObjectiveType.TALK_TO_NPC)) { - final String message = ChatColor.GREEN + "(" + BukkitLang.get(p, "completed") + ") " - + BukkitLang.get(p, "talkTo").replace("", plugin.getDependencies().getNpcName(npc)); + final String message = formatCompletedObjectiveMessage("talkTo", goal.getAmount()) + .replace("", plugin.getDependencies().getNpcName(npc)); sendMessage(message); } else if (type.equals(ObjectiveType.KILL_NPC)) { final String message = formatCompletedObjectiveMessage("kill", goal.getAmount()); @@ -3396,7 +3395,7 @@ public class BukkitQuester implements Quester { * @return Formatted message */ private String formatCompletedObjectiveMessage(final String langKey, final int goal) { - String message = ChatColor.GREEN + "(" + BukkitLang.get("completed") + ") " + BukkitLang.get(langKey); + String message = ChatColor.GREEN + "(" + BukkitLang.get(getPlayer(), "completed") + ") " + BukkitLang.get(langKey); if (message.contains("")) { message = message.replace("", goal + "/" + goal); } diff --git a/core/src/main/java/me/pikamug/quests/storage/implementation/file/BukkitQuestYamlStorage.java b/core/src/main/java/me/pikamug/quests/storage/implementation/file/BukkitQuestYamlStorage.java index 432386829..ece7740e2 100644 --- a/core/src/main/java/me/pikamug/quests/storage/implementation/file/BukkitQuestYamlStorage.java +++ b/core/src/main/java/me/pikamug/quests/storage/implementation/file/BukkitQuestYamlStorage.java @@ -788,8 +788,7 @@ public class BukkitQuestYamlStorage implements QuestStorageImpl { @SuppressWarnings({ "unchecked", "unused"}) private void loadQuestStages(final Quest quest, final FileConfiguration config, final String questKey) throws StageFormatException, ActionFormatException, ConditionFormatException { - final ConfigurationSection ordered = config.getConfigurationSection("quests." + questKey - + ".stages.ordered"); + final ConfigurationSection ordered = config.getConfigurationSection("quests." + questKey + ".stages.ordered"); if (ordered == null) { plugin.getLogger().severe(ChatColor.RED + questKey + " must have at least one stage!"); return; diff --git a/core/src/main/java/me/pikamug/quests/util/BukkitLang.java b/core/src/main/java/me/pikamug/quests/util/BukkitLang.java index 700d2e3fb..510e7e33d 100644 --- a/core/src/main/java/me/pikamug/quests/util/BukkitLang.java +++ b/core/src/main/java/me/pikamug/quests/util/BukkitLang.java @@ -46,7 +46,7 @@ public class BukkitLang { private static Quests plugin; private static final LinkedHashMap defaultLang = new LinkedHashMap<>(); private static final LinkedHashMap> otherLang = new LinkedHashMap<>(); - private static final Pattern hexPattern = Pattern.compile("(?i)%#([0-9A-F]{6})%"); + private static final Pattern hexPattern = Pattern.compile("(?i)%#([0-9a-fA-F]{6})%"); public static Collection values() { return defaultLang.values(); @@ -393,8 +393,8 @@ public class BukkitLang { final StringBuilder hex = new StringBuilder(); hex.append(ChatColor.COLOR_CHAR + "x"); final char[] chars = matcher.group(1).toCharArray(); - for (final char aChar : chars) { - hex.append(ChatColor.COLOR_CHAR).append(Character.toLowerCase(aChar)); + for (final char c : chars) { + hex.append(ChatColor.COLOR_CHAR).append(Character.toLowerCase(c)); } s = s.replace(matcher.group(), hex.toString()); }