From 054220a32ef490e34e2935aac18df57ca8c8790a Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Wed, 24 Jul 2019 19:56:36 +0200 Subject: [PATCH] Add support for extended and/or upgraded potions in the item syntax. This commit adds support for altering the data portion of a potion item by prefixing either `long_` or `strong_` to get extended duration or level II versions of the given potion, respectively. Closes #520 --- changelog.md | 1 + .../garbagemule/MobArena/util/ItemParser.java | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/changelog.md b/changelog.md index b296f41..364a0f6 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,7 @@ These changes will (most likely) be included in the next version. ## [Unreleased] +- Extended and upgraded potions are now supported in the item syntax by prepending `long_` or `strong_` to the data portion of a potion item (e.g. `potion:strong_instant_heal:1` will yield a Potion of Healing II). Check the wiki for details. - Tridents and crossbows are now considered weapons with regards to the `unbreakable-weapons` flag. All class items that have durability now have their unbreakable flag set to true unless the `unbreakable-weapons` and/or `unbreakable-armor` flags are set to `false`. - Leaderboards now work again on servers running Minecraft 1.14+. - Class chests (non-linked) now work again on servers running Minecraft 1.14+. diff --git a/src/main/java/com/garbagemule/MobArena/util/ItemParser.java b/src/main/java/com/garbagemule/MobArena/util/ItemParser.java index 98d4f0d..f89b82c 100644 --- a/src/main/java/com/garbagemule/MobArena/util/ItemParser.java +++ b/src/main/java/com/garbagemule/MobArena/util/ItemParser.java @@ -100,22 +100,28 @@ public class ItemParser } private static ItemStack withPotionMeta(ItemStack stack, String data) { - PotionType type = getPotionType(data); - if (type == null) { - return null; - } - PotionMeta meta = (PotionMeta) stack.getItemMeta(); - meta.setBasePotionData(new PotionData(type)); - stack.setItemMeta(meta); - return stack; - } + PotionType type; + boolean extended = false; + boolean upgraded = false; - private static PotionType getPotionType(String data) { + if (data.startsWith("long_")) { + extended = true; + data = data.substring(5); + } + if (data.startsWith("strong_")) { + upgraded = true; + data = data.substring(7); + } try { - return PotionType.valueOf(data.toUpperCase()); + type = PotionType.valueOf(data.toUpperCase()); } catch (IllegalArgumentException e) { return null; } + + PotionMeta meta = (PotionMeta) stack.getItemMeta(); + meta.setBasePotionData(new PotionData(type, extended, upgraded)); + stack.setItemMeta(meta); + return stack; } private static Optional getType(String item) {