Expose potion level for 1.9+, part 4. See #2232

This commit is contained in:
PikaMug 2024-08-05 04:28:02 -04:00
parent 18f571e3ee
commit 1ab2b18bfc
3 changed files with 22 additions and 4 deletions

View File

@ -1345,6 +1345,12 @@ public class BukkitQuester implements Quester {
if (formatNames) {
message = message.replace("<item>", BukkitItemUtil.getName(goal));
}
final String level = BukkitItemUtil.getPrettyPotionLevel(goal.getItemMeta());
if (level.isEmpty()) {
message = message.replace(" <level>", level);
} else {
message = message.replace("<level>", 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>", level);
} else {
message = message.replace("<level>", level);
}
}
if (!plugin.getLocaleManager().sendMessage(p, message, goal.getType(), goal.getDurability(), null)) {
sendMessage(message.replace("<item>", BukkitItemUtil.getName(is)));
}

View File

@ -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;

View File

@ -640,7 +640,7 @@ craftItem: "Craft <item>: <count>"
smeltItem: "Smelt <item>: <count>"
enchItem: "Enchant <enchantment> <level> <item>: <count>"
brewItem: "Brew <item> <level>: <count>"
consumeItem: "Consume <item>: <count>"
consumeItem: "Consume <item> <level>: <count>"
catchFish: "Catch Fish: <count>"
milkCow: "Milk Cow: <count>"
kill: "Kill <mob>: <count>"