Class PotionEffect

java.lang.Object
org.bukkit.potion.PotionEffect
All Implemented Interfaces:
ConfigurationSerializable

public class PotionEffect extends Object implements 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 Details Link icon

    • INFINITE_DURATION Link icon

      public static final int INFINITE_DURATION
      A constant denoting infinite potion duration.
      See Also:
  • Constructor Details Link icon

    • PotionEffect Link icon

      public PotionEffect(@NotNull PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles, boolean icon)
      Creates a potion effect.
      Parameters:
      type - effect type
      duration - measured in ticks, see getDuration()
      amplifier - the amplifier, see getAmplifier()
      ambient - the ambient status, see isAmbient()
      particles - the particle status, see hasParticles()
      icon - the icon status, see hasIcon()
    • PotionEffect Link icon

      public PotionEffect(@NotNull PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles)
      Creates a potion effect with no defined color.
      Parameters:
      type - effect type
      duration - measured in ticks, see getDuration()
      amplifier - the amplifier, see getAmplifier()
      ambient - the ambient status, see isAmbient()
      particles - the particle status, see hasParticles()
    • PotionEffect Link icon

      public PotionEffect(@NotNull PotionEffectType type, int duration, int amplifier, boolean ambient)
      Creates a potion effect. Assumes that particles are visible
      Parameters:
      type - effect type
      duration - measured in ticks, see getDuration()
      amplifier - the amplifier, see getAmplifier()
      ambient - the ambient status, see isAmbient()
    • PotionEffect Link icon

      public PotionEffect(@NotNull PotionEffectType type, int duration, int amplifier)
      Creates a potion effect. Assumes ambient is true.
      Parameters:
      type - Effect type
      duration - measured in ticks
      amplifier - the amplifier for the effect
      See Also:
    • PotionEffect Link icon

      public PotionEffect(@NotNull Map<String,Object> map)
      Constructor for deserialization.
      Parameters:
      map - the map to deserialize from
  • Method Details Link icon

    • serialize Link icon

      @NotNull public Map<String,Object> 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 interface ConfigurationSerializable
      Returns:
      Map containing the current state of this class
    • apply Link icon

      public boolean apply(@NotNull LivingEntity entity)
      Attempts to add the effect represented by this object to the given LivingEntity.
      Parameters:
      entity - The entity to add this effect to
      Returns:
      Whether the effect could be added
      See Also:
    • equals Link icon

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getAmplifier Link icon

      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 Link icon

      public int getDuration()
      Returns the duration (in ticks) that this effect will run for when applied to a LivingEntity.
      Returns:
      The duration of the effect, or -1 if this effect is infinite
      See Also:
    • isInfinite Link icon

      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 Link icon

      public boolean isShorterThan(@NotNull PotionEffect other)
      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 Link icon

      @NotNull public PotionEffectType getType()
      Returns the PotionEffectType of this effect.
      Returns:
      The potion type of this effect
    • isAmbient Link icon

      public boolean isAmbient()
      Makes potion effect produce more, translucent, particles.
      Returns:
      if this effect is ambient
    • hasParticles Link icon

      public boolean hasParticles()
      Returns:
      whether this effect has particles or not
    • getColor Link icon

      @Deprecated(since="1.13") @Nullable @Contract("-> null") public Color 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 Link icon

      public boolean hasIcon()
      Returns:
      whether this effect has an icon or not
    • hashCode Link icon

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object