Commits
md_5 authored 02797db500d
1 1 | package org.bukkit.potion; |
2 2 | |
3 3 | import java.util.Map; |
4 4 | import java.util.NoSuchElementException; |
5 5 | |
6 6 | import org.apache.commons.lang.Validate; |
7 + | import org.bukkit.Color; |
7 8 | import org.bukkit.configuration.serialization.ConfigurationSerializable; |
8 9 | import org.bukkit.configuration.serialization.SerializableAs; |
9 10 | import org.bukkit.entity.LivingEntity; |
10 11 | |
11 12 | import com.google.common.collect.ImmutableMap; |
12 13 | |
13 14 | /** |
14 15 | * Represents a potion effect, that can be added to a {@link LivingEntity}. A |
15 16 | * potion effect has a duration that it will last for, an amplifier that will |
16 17 | * enhance its effects, and a {@link PotionEffectType}, that represents its |
21 22 | private static final String AMPLIFIER = "amplifier"; |
22 23 | private static final String DURATION = "duration"; |
23 24 | private static final String TYPE = "effect"; |
24 25 | private static final String AMBIENT = "ambient"; |
25 26 | private static final String PARTICLES = "has-particles"; |
26 27 | private final int amplifier; |
27 28 | private final int duration; |
28 29 | private final PotionEffectType type; |
29 30 | private final boolean ambient; |
30 31 | private final boolean particles; |
32 + | private final Color color; |
31 33 | |
32 34 | /** |
33 35 | * Creates a potion effect. |
34 36 | * @param type effect type |
35 37 | * @param duration measured in ticks, see {@link |
36 38 | * PotionEffect#getDuration()} |
37 39 | * @param amplifier the amplifier, see {@link PotionEffect#getAmplifier()} |
38 40 | * @param ambient the ambient status, see {@link PotionEffect#isAmbient()} |
39 41 | * @param particles the particle status, see {@link PotionEffect#hasParticles()} |
42 + | * @param color the particle color, see {@link PotionEffect#getColor()} |
40 43 | */ |
41 - | public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles){ |
44 + | public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles, Color color){ |
42 45 | Validate.notNull(type, "effect type cannot be null"); |
43 46 | this.type = type; |
44 47 | this.duration = duration; |
45 48 | this.amplifier = amplifier; |
46 49 | this.ambient = ambient; |
47 50 | this.particles = particles; |
51 + | this.color = color; |
52 + | } |
53 + | |
54 + | /** |
55 + | * Creates a potion effect with no defined color. |
56 + | * |
57 + | * @param type effect type |
58 + | * @param duration measured in ticks, see {@link |
59 + | * PotionEffect#getDuration()} |
60 + | * @param amplifier the amplifier, see {@link PotionEffect#getAmplifier()} |
61 + | * @param ambient the ambient status, see {@link PotionEffect#isAmbient()} |
62 + | * @param particles the particle status, see {@link PotionEffect#hasParticles()} |
63 + | */ |
64 + | public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles) { |
65 + | this(type, duration, amplifier, ambient, true, null); |
48 66 | } |
49 67 | |
50 68 | /** |
51 69 | * Creates a potion effect. Assumes that particles are visible |
52 70 | * |
53 71 | * @param type effect type |
54 72 | * @param duration measured in ticks, see {@link |
55 73 | * PotionEffect#getDuration()} |
56 74 | * @param amplifier the amplifier, see {@link PotionEffect#getAmplifier()} |
57 75 | * @param ambient the ambient status, see {@link PotionEffect#isAmbient()} |
179 197 | return ambient; |
180 198 | } |
181 199 | |
182 200 | /** |
183 201 | * @return whether this effect has particles or not |
184 202 | */ |
185 203 | public boolean hasParticles(){ |
186 204 | return particles; |
187 205 | } |
188 206 | |
207 + | /** |
208 + | * @return color of this potion's particles. May be null if the potion has no particles or defined color. |
209 + | */ |
210 + | public Color getColor() { |
211 + | return color; |
212 + | } |
213 + | |
189 214 | |
190 215 | public int hashCode() { |
191 216 | int hash = 1; |
192 217 | hash = hash * 31 + type.hashCode(); |
193 218 | hash = hash * 31 + amplifier; |
194 219 | hash = hash * 31 + duration; |
195 220 | hash ^= 0x22222222 >> (ambient ? 1 : -1); |
196 221 | hash ^= 0x22222222 >> (particles ? 1 : -1); |
197 222 | return hash; |
198 223 | } |