SPIGOT-4217: Account for ShowIcon to allow custom tipped arrows to merge

By: md_5 <git@md-5.net>
This commit is contained in:
Bukkit/Spigot 2018-08-03 19:57:02 +10:00
parent 3bf93e2e0f
commit 22c1a2b605

View file

@ -24,12 +24,13 @@ public class PotionEffect implements ConfigurationSerializable {
private static final String TYPE = "effect"; private static final String TYPE = "effect";
private static final String AMBIENT = "ambient"; private static final String AMBIENT = "ambient";
private static final String PARTICLES = "has-particles"; private static final String PARTICLES = "has-particles";
private static final String ICON = "has-icon";
private final int amplifier; private final int amplifier;
private final int duration; private final int duration;
private final PotionEffectType type; private final PotionEffectType type;
private final boolean ambient; private final boolean ambient;
private final boolean particles; private final boolean particles;
private final Color color; private final boolean icon;
/** /**
* Creates a potion effect. * Creates a potion effect.
@ -39,16 +40,16 @@ public class PotionEffect implements ConfigurationSerializable {
* @param amplifier the amplifier, see {@link PotionEffect#getAmplifier()} * @param amplifier the amplifier, see {@link PotionEffect#getAmplifier()}
* @param ambient the ambient status, see {@link PotionEffect#isAmbient()} * @param ambient the ambient status, see {@link PotionEffect#isAmbient()}
* @param particles the particle status, see {@link PotionEffect#hasParticles()} * @param particles the particle status, see {@link PotionEffect#hasParticles()}
* @param color the particle color, see {@link PotionEffect#getColor()} * @param icon the icon status, see {@link PotionEffect#hasIcon()}
*/ */
public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles, Color color) { public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles, boolean icon) {
Validate.notNull(type, "effect type cannot be null"); Validate.notNull(type, "effect type cannot be null");
this.type = type; this.type = type;
this.duration = duration; this.duration = duration;
this.amplifier = amplifier; this.amplifier = amplifier;
this.ambient = ambient; this.ambient = ambient;
this.particles = particles; this.particles = particles;
this.color = color; this.icon = icon;
} }
/** /**
@ -62,7 +63,7 @@ public class PotionEffect implements ConfigurationSerializable {
* @param particles the particle status, see {@link PotionEffect#hasParticles()} * @param particles the particle status, see {@link PotionEffect#hasParticles()}
*/ */
public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles) { public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles) {
this(type, duration, amplifier, ambient, particles, null); this(type, duration, amplifier, ambient, particles, particles);
} }
/** /**
@ -96,7 +97,7 @@ public class PotionEffect implements ConfigurationSerializable {
* @param map the map to deserialize from * @param map the map to deserialize from
*/ */
public PotionEffect(Map<String, Object> map) { public PotionEffect(Map<String, Object> map) {
this(getEffectType(map), getInt(map, DURATION), getInt(map, AMPLIFIER), getBool(map, AMBIENT, false), getBool(map, PARTICLES, true)); this(getEffectType(map), getInt(map, DURATION), getInt(map, AMPLIFIER), getBool(map, AMBIENT, false), getBool(map, PARTICLES, true), getBool(map, ICON, getBool(map, PARTICLES, true)));
} }
private static PotionEffectType getEffectType(Map<?, ?> map) { private static PotionEffectType getEffectType(Map<?, ?> map) {
@ -125,13 +126,14 @@ public class PotionEffect implements ConfigurationSerializable {
} }
public Map<String, Object> serialize() { public Map<String, Object> serialize() {
return ImmutableMap.<String, Object>of( return ImmutableMap.<String, Object>builder()
TYPE, type.getId(), .put(TYPE, type.getId())
DURATION, duration, .put(DURATION, duration)
AMPLIFIER, amplifier, .put(AMPLIFIER, amplifier)
AMBIENT, ambient, .put(AMBIENT, ambient)
PARTICLES, particles .put(PARTICLES, particles)
); .put(ICON, icon)
.build();
} }
/** /**
@ -155,7 +157,7 @@ public class PotionEffect implements ConfigurationSerializable {
return false; return false;
} }
PotionEffect that = (PotionEffect) obj; PotionEffect that = (PotionEffect) obj;
return this.type.equals(that.type) && this.ambient == that.ambient && this.amplifier == that.amplifier && this.duration == that.duration && this.particles == that.particles; return this.type.equals(that.type) && this.ambient == that.ambient && this.amplifier == that.amplifier && this.duration == that.duration && this.particles == that.particles && this.icon == that.icon;
} }
/** /**
@ -206,9 +208,18 @@ public class PotionEffect implements ConfigurationSerializable {
/** /**
* @return color of this potion's particles. May be null if the potion has no particles or defined color. * @return color of this potion's particles. May be null if the potion has no particles or defined color.
* @deprecated color is not part of potion effects
*/ */
@Deprecated
public Color getColor() { public Color getColor() {
return color; return null;
}
/**
* @return whether this effect has an icon or not
*/
public boolean hasIcon() {
return icon;
} }
@Override @Override
@ -219,6 +230,7 @@ public class PotionEffect implements ConfigurationSerializable {
hash = hash * 31 + duration; hash = hash * 31 + duration;
hash ^= 0x22222222 >> (ambient ? 1 : -1); hash ^= 0x22222222 >> (ambient ? 1 : -1);
hash ^= 0x22222222 >> (particles ? 1 : -1); hash ^= 0x22222222 >> (particles ? 1 : -1);
hash ^= 0x22222222 >> (icon ? 1 : -1);
return hash; return hash;
} }