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.- Since:
- 1.1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA constant denoting infinite potion duration. -
Constructor Summary
ConstructorsConstructorDescriptionPotionEffect(@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 TypeMethodDescriptionbooleanapply(@NotNull LivingEntity entity) Attempts to add the effect represented by this object to the givenLivingEntity.booleanintReturns the amplifier of this effect.@Nullable ColorgetColor()Deprecated.color is not part of potion effectsintReturns the duration (in ticks) that this effect will run for when applied to aLivingEntity.@Nullable PotionEffectReturns the PotionEffect that will become active after the current PotionEffect has run out.@NotNull PotionEffectTypegetType()Returns thePotionEffectTypeof this effect.inthashCode()booleanhasIcon()booleanbooleanMakes potion effect produce more, translucent, particles.booleanReturns whether or not this potion effect has an infinite duration.booleanisShorterThan(@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()@NotNull PotionEffectwithAmbient(boolean ambient) Returns a new potion effect with the provided ambient and this effect's type, duration, amplifier, particles, and icon.@NotNull PotionEffectwithAmplifier(int amplifier) Returns a new potion effect with the provided amplifier and this effect's type, duration, ambient, particles, and icon.@NotNull PotionEffectwithDuration(int duration) Returns a new potion effect with the provided duration and this effect's type, amplifier, ambient, particles, and icon.@NotNull PotionEffectwithIcon(boolean icon) Returns a new potion effect with the provided icon and this effect's type, duration, amplifier, ambient, and particles.@NotNull PotionEffectwithParticles(boolean particles) Returns a new potion effect with the provided particles and this effect's type, duration, amplifier, ambient, and icon.@NotNull PotionEffectwithType(@NotNull PotionEffectType type) Returns a new potion effect with the provided type and this effect's duration, amplifier, ambient, particles, and icon.
-
Field Details
-
INFINITE_DURATION
public static final int INFINITE_DURATIONA constant denoting infinite potion duration.- Since:
- 1.19.4
- 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()- Since:
- 1.13
-
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()- Since:
- 1.8
-
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()- Since:
- 1.4.5
-
PotionEffect
Creates a potion effect. Assumes ambient is true.- Parameters:
type- Effect typeduration- measured in ticksamplifier- the amplifier for the effect- Since:
- 1.1.0
- See Also:
-
PotionEffect
-
-
Method Details
-
withType
Returns a new potion effect with the provided type and this effect's duration, amplifier, ambient, particles, and icon.- Parameters:
type- effect type- Returns:
- a new potion effect with the provided type
- Since:
- 1.12.2
-
withDuration
Returns a new potion effect with the provided duration and this effect's type, amplifier, ambient, particles, and icon.- Parameters:
duration- measured in ticks, seegetDuration()- Returns:
- a new potion effect with the provided duration
- Since:
- 1.12.2
-
withAmplifier
Returns a new potion effect with the provided amplifier and this effect's type, duration, ambient, particles, and icon.- Parameters:
amplifier- the amplifier, seegetAmplifier()- Returns:
- a new potion effect with the provided amplifier
- Since:
- 1.12.2
-
withAmbient
Returns a new potion effect with the provided ambient and this effect's type, duration, amplifier, particles, and icon.- Parameters:
ambient- the ambient status, seeisAmbient()- Returns:
- a new potion effect with the provided ambient
- Since:
- 1.12.2
-
withParticles
Returns a new potion effect with the provided particles and this effect's type, duration, amplifier, ambient, and icon.- Parameters:
particles- the particle status, seehasParticles()- Returns:
- a new potion effect with the provided particles
- Since:
- 1.12.2
-
withIcon
Returns a new potion effect with the provided icon and this effect's type, duration, amplifier, ambient, and particles.- Parameters:
icon- the icon status, seehasIcon()- Returns:
- a new potion effect with the provided icon
- Since:
- 1.13
-
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.
- Since:
- 1.20.4
-
serialize
Description copied from interface:ConfigurationSerializableCreates a Map representation of this class.This class must provide a method to restore this class, as defined in the
ConfigurationSerializableinterface javadocs. nb: It is not intended for this method to be called directly, this will be called by theConfigurationSerializationclass.- Specified by:
serializein interfaceConfigurationSerializable- Returns:
- Map containing the current state of this class
- Since:
- 1.4.5
-
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
- Since:
- 1.1.0
- 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
- Since:
- 1.1.0
-
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
- Since:
- 1.1.0
- 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
- Since:
- 1.19.4
-
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
- Since:
- 1.19.4
-
getType
Returns thePotionEffectTypeof this effect.- Returns:
- The potion type of this effect
- Since:
- 1.1.0
-
isAmbient
public boolean isAmbient()Makes potion effect produce more, translucent, particles.- Returns:
- if this effect is ambient
- Since:
- 1.4.5
-
hasParticles
public boolean hasParticles()- Returns:
- whether this effect has particles or not
- Since:
- 1.8
-
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.
- Since:
- 1.9.4
-
hasIcon
public boolean hasIcon()- Returns:
- whether this effect has an icon or not
- Since:
- 1.13
-
hashCode
-
toString
-