Package org.bukkit.potion
Class PotionEffect
java.lang.Object
org.bukkit.potion.PotionEffect
- All Implemented Interfaces:
ConfigurationSerializable
Represents a potion effect, that can be added to a
LivingEntity
. A
potion effect has a duration that it will last for, an amplifier that will
enhance its effects, and a PotionEffectType
, that represents its
effect on an entity.-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
A constant denoting infinite potion duration. -
Constructor Summary
ConstructorDescriptionPotionEffect
(@NotNull Map<String, Object> map) Constructor for deserialization.PotionEffect
(@NotNull PotionEffectType type, int duration, int amplifier) Creates a potion effect.PotionEffect
(@NotNull PotionEffectType type, int duration, int amplifier, boolean ambient) Creates a potion effect.PotionEffect
(@NotNull PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles) Creates a potion effect with no defined color.PotionEffect
(@NotNull PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles, boolean icon) Creates a potion effect. -
Method Summary
Modifier and TypeMethodDescriptionboolean
apply
(@NotNull LivingEntity entity) Attempts to add the effect represented by this object to the givenLivingEntity
.boolean
int
Returns the amplifier of this effect.getColor()
Deprecated.color is not part of potion effectsint
Returns the duration (in ticks) that this effect will run for when applied to aLivingEntity
.Returns the PotionEffect that will become active after the current PotionEffect has run out.getType()
Returns thePotionEffectType
of this effect.int
hashCode()
boolean
hasIcon()
boolean
boolean
Makes potion effect produce more, translucent, particles.boolean
Returns whether or not this potion effect has an infinite duration.boolean
isShorterThan
(@NotNull PotionEffect other) Returns whether or not this potion effect has a shorter duration than the provided potion effect.Creates a Map representation of this class.toString()
withAmbient
(boolean ambient) withAmplifier
(int amplifier) withDuration
(int duration) withIcon
(boolean icon) withParticles
(boolean particles) withType
(@NotNull PotionEffectType type)
-
Field Details
-
INFINITE_DURATION
public static final int INFINITE_DURATIONA constant denoting infinite potion duration.- See Also:
-
-
Constructor Details
-
PotionEffect
public PotionEffect(@NotNull @NotNull PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles, boolean icon) Creates a potion effect.- Parameters:
type
- effect typeduration
- measured in ticks, seegetDuration()
amplifier
- the amplifier, seegetAmplifier()
ambient
- the ambient status, seeisAmbient()
particles
- the particle status, seehasParticles()
icon
- the icon status, seehasIcon()
-
PotionEffect
public PotionEffect(@NotNull @NotNull PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles) Creates a potion effect with no defined color.- Parameters:
type
- effect typeduration
- measured in ticks, seegetDuration()
amplifier
- the amplifier, seegetAmplifier()
ambient
- the ambient status, seeisAmbient()
particles
- the particle status, seehasParticles()
-
PotionEffect
public PotionEffect(@NotNull @NotNull PotionEffectType type, int duration, int amplifier, boolean ambient) Creates a potion effect. Assumes that particles are visible- Parameters:
type
- effect typeduration
- measured in ticks, seegetDuration()
amplifier
- the amplifier, seegetAmplifier()
ambient
- the ambient status, seeisAmbient()
-
PotionEffect
Creates a potion effect. Assumes ambient is true.- Parameters:
type
- Effect typeduration
- measured in ticksamplifier
- the amplifier for the effect- See Also:
-
PotionEffect
Constructor for deserialization.- Parameters:
map
- the map to deserialize from
-
-
Method Details
-
withType
-
withDuration
-
withAmplifier
-
withAmbient
-
withParticles
-
withIcon
-
getHiddenPotionEffect
Returns the PotionEffect that will become active after the current PotionEffect has run out.Note: This value is only applicable to type applied to living entities.
- Returns:
- The hidden PotionEffect.
-
serialize
Description copied from interface:ConfigurationSerializable
Creates a Map representation of this class.This class must provide a method to restore this class, as defined in the
ConfigurationSerializable
interface javadocs.- Specified by:
serialize
in interfaceConfigurationSerializable
- Returns:
- Map containing the current state of this class
-
apply
Attempts to add the effect represented by this object to the givenLivingEntity
.Note:
getHiddenPotionEffect()
is ignored when adding the effect to the entity.- Parameters:
entity
- The entity to add this effect to- Returns:
- Whether the effect could be added
- See Also:
-
equals
-
getAmplifier
public int getAmplifier()Returns the amplifier of this effect. A higher amplifier means the potion effect happens more often over its duration and in some cases has more effect on its target.- Returns:
- The effect amplifier
-
getDuration
public int getDuration()Returns the duration (in ticks) that this effect will run for when applied to aLivingEntity
.- Returns:
- The duration of the effect, or -1 if this effect is infinite
- See Also:
-
isInfinite
public boolean isInfinite()Returns whether or not this potion effect has an infinite duration. Potion effects with infinite durations will display an infinite symbol and never expire unless manually removed.- Returns:
- whether this duration is infinite or not
-
isShorterThan
Returns whether or not this potion effect has a shorter duration than the provided potion effect.An infinite duration is considered longer than non-infinite durations. If both potion effects have infinite durations, then neither is shorter than the other and this method will return false.
- Parameters:
other
- the other effect- Returns:
- true if this effect is shorter than the other, false if longer or equal
-
getType
Returns thePotionEffectType
of this effect.- Returns:
- The potion type of this effect
-
isAmbient
public boolean isAmbient()Makes potion effect produce more, translucent, particles.- Returns:
- if this effect is ambient
-
hasParticles
public boolean hasParticles()- Returns:
- whether this effect has particles or not
-
getColor
Deprecated.color is not part of potion effects- Returns:
- color of this potion's particles. May be null if the potion has no particles or defined color.
-
hasIcon
public boolean hasIcon()- Returns:
- whether this effect has an icon or not
-
hashCode
public int hashCode() -
toString
-