From 8f84f08506c18b46f3975d9c0192664e4fff1822 Mon Sep 17 00:00:00 2001 From: Thinkofdeath Date: Wed, 11 Mar 2015 11:53:20 +0000 Subject: SPIGOT-678: Fix the particles flag being ignored in hashCode, equals and serialization --- src/main/java/org/bukkit/potion/PotionEffect.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bukkit/potion/PotionEffect.java b/src/main/java/org/bukkit/potion/PotionEffect.java index 01503f49..75bfa27a 100644 --- a/src/main/java/org/bukkit/potion/PotionEffect.java +++ b/src/main/java/org/bukkit/potion/PotionEffect.java @@ -22,6 +22,7 @@ public class PotionEffect implements ConfigurationSerializable { private static final String DURATION = "duration"; private static final String TYPE = "effect"; private static final String AMBIENT = "ambient"; + private static final String PARTICLES = "has-particles"; private final int amplifier; private final int duration; private final PotionEffectType type; @@ -77,7 +78,7 @@ public class PotionEffect implements ConfigurationSerializable { * @param map the map to deserialize from */ public PotionEffect(Map map) { - this(getEffectType(map), getInt(map, DURATION), getInt(map, AMPLIFIER), getBool(map, AMBIENT)); + this(getEffectType(map), getInt(map, DURATION), getInt(map, AMPLIFIER), getBool(map, AMBIENT, false), getBool(map, PARTICLES, true)); } private static PotionEffectType getEffectType(Map map) { @@ -97,12 +98,12 @@ public class PotionEffect implements ConfigurationSerializable { throw new NoSuchElementException(map + " does not contain " + key); } - private static boolean getBool(Map map, Object key) { + private static boolean getBool(Map map, Object key, boolean def) { Object bool = map.get(key); if (bool instanceof Boolean) { return (Boolean) bool; } - throw new NoSuchElementException(map + " does not contain " + key); + return def; } public Map serialize() { @@ -110,7 +111,8 @@ public class PotionEffect implements ConfigurationSerializable { TYPE, type.getId(), DURATION, duration, AMPLIFIER, amplifier, - AMBIENT, ambient + AMBIENT, ambient, + PARTICLES, particles ); } @@ -135,7 +137,7 @@ public class PotionEffect implements ConfigurationSerializable { return false; } PotionEffect that = (PotionEffect) obj; - return this.type.equals(that.type) && this.ambient == that.ambient && this.amplifier == that.amplifier && this.duration == that.duration; + return this.type.equals(that.type) && this.ambient == that.ambient && this.amplifier == that.amplifier && this.duration == that.duration && this.particles == that.particles; } /** @@ -191,6 +193,7 @@ public class PotionEffect implements ConfigurationSerializable { hash = hash * 31 + amplifier; hash = hash * 31 + duration; hash ^= 0x22222222 >> (ambient ? 1 : -1); + hash ^= 0x22222222 >> (particles ? 1 : -1); return hash; } -- cgit v1.2.3