Class PotionEffect

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

public class PotionEffect
extends java.lang.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.
  • Constructor Summary

    Constructors 
    Constructor Description
    PotionEffect​(java.util.Map<java.lang.String,​java.lang.Object> map)
    Constructor for deserialization.
    PotionEffect​(PotionEffectType type, int duration, int amplifier)
    Creates a potion effect.
    PotionEffect​(PotionEffectType type, int duration, int amplifier, boolean ambient)
    Creates a potion effect.
    PotionEffect​(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles)
    Creates a potion effect.
  • Method Summary

    Modifier and Type Method Description
    boolean apply​(LivingEntity entity)
    Attempts to add the effect represented by this object to the given LivingEntity.
    boolean equals​(java.lang.Object obj)  
    int getAmplifier()
    Returns the amplifier of this effect.
    int getDuration()
    Returns the duration (in ticks) that this effect will run for when applied to a LivingEntity.
    PotionEffectType getType()
    Returns the PotionEffectType of this effect.
    int hashCode()  
    boolean hasParticles()  
    boolean isAmbient()
    Makes potion effect produce more, translucent, particles.
    java.util.Map<java.lang.String,​java.lang.Object> serialize()
    Creates a Map representation of this class.
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • PotionEffect

      public PotionEffect​(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles)
      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()
    • PotionEffect

      public PotionEffect​(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

      public PotionEffect​(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(PotionEffectType, int, int, boolean)
    • PotionEffect

      public PotionEffect​(java.util.Map<java.lang.String,​java.lang.Object> map)
      Constructor for deserialization.
      Parameters:
      map - the map to deserialize from
  • Method Details

    • serialize

      public java.util.Map<java.lang.String,​java.lang.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

      public boolean apply​(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:
      LivingEntity.addPotionEffect(PotionEffect)
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • 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 a LivingEntity.
      Returns:
      The duration of the effect
    • getType

      public PotionEffectType getType()
      Returns the PotionEffectType 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
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object