From 1ab2b18bfcc73e2dc8cd09b4a9c4efdd1dda56e1 Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Mon, 5 Aug 2024 04:28:02 -0400 Subject: [PATCH] Expose potion level for 1.9+, part 4. See #2232 --- .../me/pikamug/quests/player/BukkitQuester.java | 17 ++++++++++++++++- .../me/pikamug/quests/util/BukkitItemUtil.java | 7 +++++-- core/src/main/resources/strings.yml | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) 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 7b72c462a..a759c0cc1 100644 --- a/core/src/main/java/me/pikamug/quests/player/BukkitQuester.java +++ b/core/src/main/java/me/pikamug/quests/player/BukkitQuester.java @@ -1345,6 +1345,12 @@ public class BukkitQuester implements Quester { if (formatNames) { message = message.replace("", BukkitItemUtil.getName(goal)); } + final String level = BukkitItemUtil.getPrettyPotionLevel(goal.getItemMeta()); + if (level.isEmpty()) { + message = message.replace(" ", level); + } else { + message = message.replace("", level); + } objectives.add(new BukkitObjective(ObjectiveType.CONSUME_ITEM, message, progress, goal)); } for (int i = 0; i < data.getItemsDelivered().size(); i++) { @@ -3347,9 +3353,18 @@ public class BukkitQuester implements Quester { } else if (type.equals(ObjectiveType.CONSUME_ITEM)) { final ItemStack is = ((BukkitStage) getCurrentStage(quest)).getItemsToConsume().get(getCurrentStage(quest) .getItemsToConsume().indexOf(goal)); - final String message = formatCompletedObjectiveMessage("consumeItem", goal.getAmount()); + String message = formatCompletedObjectiveMessage("consumeItem", goal.getAmount()); if (plugin.getConfigSettings().canTranslateNames() && !goal.hasItemMeta() && !goal.getItemMeta().hasDisplayName()) { + // Bukkit version is 1.9+ + if (goal.getType().name().contains("POTION") && plugin.getLocaleManager().hasBasePotionData()) { + final String level = BukkitItemUtil.getPrettyPotionLevel(goal.getItemMeta()); + if (level.isEmpty()) { + message = message.replace(" ", level); + } else { + message = message.replace("", level); + } + } if (!plugin.getLocaleManager().sendMessage(p, message, goal.getType(), goal.getDurability(), null)) { sendMessage(message.replace("", BukkitItemUtil.getName(is))); } diff --git a/core/src/main/java/me/pikamug/quests/util/BukkitItemUtil.java b/core/src/main/java/me/pikamug/quests/util/BukkitItemUtil.java index 61726bb31..35410e30d 100644 --- a/core/src/main/java/me/pikamug/quests/util/BukkitItemUtil.java +++ b/core/src/main/java/me/pikamug/quests/util/BukkitItemUtil.java @@ -780,11 +780,14 @@ public class BukkitItemUtil { if (Material.getMaterial("LINGERING_POTION") == null) { return prettyString; } + if (!(itemMeta instanceof PotionMeta)) { + return prettyString; + } final PotionMeta meta = (PotionMeta) itemMeta; - if (meta != null && meta.getBasePotionData().isUpgraded()) { + if (meta.getBasePotionData().isUpgraded()) { final int level = meta.getBasePotionData().getType().name().contains("SLOWNESS") ? 4 : 2; prettyString = ChatColor.GREEN + RomanNumeral.getNumeral(level) + ChatColor.RESET; - } else if (meta != null && meta.getBasePotionData().isExtended()) { + } else if (meta.getBasePotionData().isExtended()) { prettyString = ChatColor.GREEN + "+" + ChatColor.RESET; } return prettyString; diff --git a/core/src/main/resources/strings.yml b/core/src/main/resources/strings.yml index f784c7506..401c8002a 100644 --- a/core/src/main/resources/strings.yml +++ b/core/src/main/resources/strings.yml @@ -640,7 +640,7 @@ craftItem: "Craft : " smeltItem: "Smelt : " enchItem: "Enchant : " brewItem: "Brew : " -consumeItem: "Consume : " +consumeItem: "Consume : " catchFish: "Catch Fish: " milkCow: "Milk Cow: " kill: "Kill : "