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) { if (formatNames) {
message = message.replace("<item>", BukkitItemUtil.getName(goal)); 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)); objectives.add(new BukkitObjective(ObjectiveType.CONSUME_ITEM, message, progress, goal));
} }
for (int i = 0; i < data.getItemsDelivered().size(); i++) { 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)) { } else if (type.equals(ObjectiveType.CONSUME_ITEM)) {
final ItemStack is = ((BukkitStage) getCurrentStage(quest)).getItemsToConsume().get(getCurrentStage(quest) final ItemStack is = ((BukkitStage) getCurrentStage(quest)).getItemsToConsume().get(getCurrentStage(quest)
.getItemsToConsume().indexOf(goal)); .getItemsToConsume().indexOf(goal));
final String message = formatCompletedObjectiveMessage("consumeItem", goal.getAmount()); String message = formatCompletedObjectiveMessage("consumeItem", goal.getAmount());
if (plugin.getConfigSettings().canTranslateNames() && !goal.hasItemMeta() if (plugin.getConfigSettings().canTranslateNames() && !goal.hasItemMeta()
&& !goal.getItemMeta().hasDisplayName()) { && !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)) { if (!plugin.getLocaleManager().sendMessage(p, message, goal.getType(), goal.getDurability(), null)) {
sendMessage(message.replace("<item>", BukkitItemUtil.getName(is))); sendMessage(message.replace("<item>", BukkitItemUtil.getName(is)));
} }

View File

@ -780,11 +780,14 @@ public class BukkitItemUtil {
if (Material.getMaterial("LINGERING_POTION") == null) { if (Material.getMaterial("LINGERING_POTION") == null) {
return prettyString; return prettyString;
} }
if (!(itemMeta instanceof PotionMeta)) {
return prettyString;
}
final PotionMeta meta = (PotionMeta) itemMeta; 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; final int level = meta.getBasePotionData().getType().name().contains("SLOWNESS") ? 4 : 2;
prettyString = ChatColor.GREEN + RomanNumeral.getNumeral(level) + ChatColor.RESET; 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; prettyString = ChatColor.GREEN + "+" + ChatColor.RESET;
} }
return prettyString; return prettyString;

View File

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