Commits

Hex authored and md_5 committed 935e6dd9397
Add API to PotionEffect to determine whether particles are visible and displayed to the client.

Fixes SPIGOT-125
No tags

src/main/java/org/bukkit/potion/PotionEffect.java

Modified
19 19 @SerializableAs("PotionEffect")
20 20 public class PotionEffect implements ConfigurationSerializable {
21 21 private static final String AMPLIFIER = "amplifier";
22 22 private static final String DURATION = "duration";
23 23 private static final String TYPE = "effect";
24 24 private static final String AMBIENT = "ambient";
25 25 private final int amplifier;
26 26 private final int duration;
27 27 private final PotionEffectType type;
28 28 private final boolean ambient;
29 + private final boolean particles;
29 30
30 31 /**
31 32 * Creates a potion effect.
32 - *
33 33 * @param type effect type
34 34 * @param duration measured in ticks, see {@link
35 35 * PotionEffect#getDuration()}
36 36 * @param amplifier the amplifier, see {@link PotionEffect#getAmplifier()}
37 37 * @param ambient the ambient status, see {@link PotionEffect#isAmbient()}
38 + * @param particles the particle status, see {@link PotionEffect#hasParticles()}
38 39 */
39 - public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient) {
40 + public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles){
40 41 Validate.notNull(type, "effect type cannot be null");
41 42 this.type = type;
42 43 this.duration = duration;
43 44 this.amplifier = amplifier;
44 45 this.ambient = ambient;
46 + this.particles = particles;
47 + }
48 +
49 + /**
50 + * Creates a potion effect. Assumes that particles are visible
51 + *
52 + * @param type effect type
53 + * @param duration measured in ticks, see {@link
54 + * PotionEffect#getDuration()}
55 + * @param amplifier the amplifier, see {@link PotionEffect#getAmplifier()}
56 + * @param ambient the ambient status, see {@link PotionEffect#isAmbient()}
57 + */
58 + public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient) {
59 + this(type, duration, amplifier, ambient, true);
45 60 }
46 61
47 62 /**
48 63 * Creates a potion effect. Assumes ambient is true.
49 64 *
50 65 * @param type Effect type
51 66 * @param duration measured in ticks
52 67 * @param amplifier the amplifier for the effect
53 68 * @see PotionEffect#PotionEffect(PotionEffectType, int, int, boolean)
54 69 */
155 170
156 171 /**
157 172 * Makes potion effect produce more, translucent, particles.
158 173 *
159 174 * @return if this effect is ambient
160 175 */
161 176 public boolean isAmbient() {
162 177 return ambient;
163 178 }
164 179
180 + /**
181 + * @return whether this effect has particles or not
182 + */
183 + public boolean hasParticles(){
184 + return particles;
185 + }
186 +
165 187 @Override
166 188 public int hashCode() {
167 189 int hash = 1;
168 190 hash = hash * 31 + type.hashCode();
169 191 hash = hash * 31 + amplifier;
170 192 hash = hash * 31 + duration;
171 193 hash ^= 0x22222222 >> (ambient ? 1 : -1);
172 194 return hash;
173 195 }
174 196

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut