From f92f48cbd08c37008ccf9bcd0c30efcba54a9fc8 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sat, 27 Jul 2013 10:07:56 +0200 Subject: [PATCH] Workaround BUKKIT-4612 --- src/com/massivecraft/mcore/util/MUtil.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/com/massivecraft/mcore/util/MUtil.java b/src/com/massivecraft/mcore/util/MUtil.java index bbdc6d0c..a6c7ef17 100644 --- a/src/com/massivecraft/mcore/util/MUtil.java +++ b/src/com/massivecraft/mcore/util/MUtil.java @@ -303,6 +303,19 @@ public class MUtil // POTION DERP // -------------------------------------------- // + /** + * Get just the potion effect bits. This is to work around bugs with potion parsing. + * Workaround created by the WorldGuard team: https://github.com/sk89q/worldguard/commit/8dec32fa6a1238a11743cea8b8302a6c9d2aaa55 + * This issue is reported as BUKKIT-4612 "Potion.fromItemStack causes IllegalArgumentException: Instant potions cannot be extended" + * + * @param item item + * @return new bits + */ + public static int getPotionEffectBits(ItemStack item) + { + return item.getDurability() & 0x3F; + } + public static List getPotionEffects(ItemStack itemStack) { if (itemStack == null) return null; @@ -310,7 +323,7 @@ public class MUtil List ret = new ArrayList(); - Potion potion = Potion.fromItemStack(itemStack); + Potion potion = Potion.fromDamage(getPotionEffectBits(itemStack)); ret.addAll(potion.getEffects()); PotionMeta meta = (PotionMeta) itemStack.getItemMeta();