From c19f8ba06184a62501600e1b4c7de5416a185e36 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 21 Dec 2012 12:45:32 +0100 Subject: [PATCH] Made the PotionEffectAdapter a bit more flexible --- .../mcore5/adapter/PotionEffectAdapter.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/com/massivecraft/mcore5/adapter/PotionEffectAdapter.java b/src/com/massivecraft/mcore5/adapter/PotionEffectAdapter.java index 15917e00..a60f9ee0 100644 --- a/src/com/massivecraft/mcore5/adapter/PotionEffectAdapter.java +++ b/src/com/massivecraft/mcore5/adapter/PotionEffectAdapter.java @@ -17,6 +17,10 @@ public class PotionEffectAdapter public static final String POTION_AMPLIFIER = "amplifier"; public static final String POTION_AMBIENT = "ambient"; + public static final int POTION_DURATION_DEFAULT = 20*3*60; + public static final int POTION_AMPLIFIER_DEFAULT = 0; + public static final boolean POTION_AMBIENT_DEFAULT = false; + // -------------------------------------------- // // TO JSON // -------------------------------------------- // @@ -47,9 +51,27 @@ public class PotionEffectAdapter JsonObject json = jsonElement.getAsJsonObject(); PotionEffectType pet = PotionEffectType.getById(json.get(POTION_EFFECT_ID).getAsInt()); - int duration = json.get(POTION_DURATION).getAsInt(); - int amplifier = json.get(POTION_AMPLIFIER).getAsInt(); - boolean ambient = json.get(POTION_AMBIENT).getAsBoolean(); + + int duration = POTION_DURATION_DEFAULT; + JsonElement durationElement = json.get(POTION_DURATION); + if (durationElement != null) + { + duration = durationElement.getAsInt(); + } + + int amplifier = POTION_AMPLIFIER_DEFAULT; + JsonElement amplifierElement = json.get(POTION_AMPLIFIER); + if (amplifierElement != null) + { + amplifier = amplifierElement.getAsInt(); + } + + boolean ambient = POTION_AMBIENT_DEFAULT; + JsonElement ambientElement = json.get(POTION_AMBIENT); + if (ambientElement != null) + { + ambient = ambientElement.getAsBoolean(); + } return new PotionEffect(pet, duration, amplifier, ambient); }