From d676d231bd51c5102ab6b62eb7457f0df1f5567e Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 14 Mar 2016 18:36:50 +0100 Subject: [PATCH] Fix issue with water and uncraftable. --- .../adapter/ItemStackAdapterInner19.java | 48 ++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/src/com/massivecraft/massivecore/adapter/ItemStackAdapterInner19.java b/src/com/massivecraft/massivecore/adapter/ItemStackAdapterInner19.java index bb56720c..f0bf0a79 100644 --- a/src/com/massivecraft/massivecore/adapter/ItemStackAdapterInner19.java +++ b/src/com/massivecraft/massivecore/adapter/ItemStackAdapterInner19.java @@ -21,7 +21,7 @@ public class ItemStackAdapterInner19 extends ItemStackAdapterInner18 // -------------------------------------------- // public static final String POTION = "potion"; - public static final PotionData POTION_DEFAULT = new PotionData(PotionType.UNCRAFTABLE, false, false); + public static final PotionData POTION_DEFAULT = new PotionData(PotionType.WATER, false, false); // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -59,9 +59,11 @@ public class ItemStackAdapterInner19 extends ItemStackAdapterInner18 if (meta2json) { + // Check Null and Default PotionData potionData = meta.getBasePotionData(); if (potionData != null && ! potionData.equals(POTION_DEFAULT)) { + // Check Null (silent on failure) String potionString = toPotionString(potionData); if (potionString != null) { @@ -71,6 +73,10 @@ public class ItemStackAdapterInner19 extends ItemStackAdapterInner18 } else { + // Create + PotionData target = null; + + // Get by "potion" JsonElement potionElement = json.get(POTION); if (potionElement != null) { @@ -78,22 +84,34 @@ public class ItemStackAdapterInner19 extends ItemStackAdapterInner18 PotionData potionData = toPotionData(potionString); if (potionData != null) { - meta.setBasePotionData(potionData); + target = potionData; } - return; } - - JsonElement damageElement = json.get(DAMAGE); - if (damageElement != null) + + // Get by "damage" + if (target == null) { - int damage = damageElement.getAsInt(); - PotionData potionData = toPotionData(damage); - if (potionData != null) + JsonElement damageElement = json.get(DAMAGE); + if (damageElement != null) { - meta.setBasePotionData(potionData); - stack.setDurability((short) 0); + int damage = damageElement.getAsInt(); + PotionData potionData = toPotionData(damage); + if (potionData != null) + { + stack.setDurability((short) 0); + target = potionData; + } } } + + // Get by POTION_DEFAULT + if (target == null) + { + target = POTION_DEFAULT; + } + + // Set + meta.setBasePotionData(target); } } @@ -109,6 +127,14 @@ public class ItemStackAdapterInner19 extends ItemStackAdapterInner18 PotionType type = potion.getType(); boolean extended = potion.hasExtendedDuration(); boolean upgraded = (potion.getLevel() >= 2); + + // Try to avoid slow exceptions. + // The same checks are done in the PotionData constructor. + if (type == null) return null; + if (extended && ! type.isExtendable()) return null; + if (upgraded && ! type.isUpgradeable()) return null; + if (upgraded && extended) return null; + return new PotionData(type, extended, upgraded); } catch (Exception e)