Class SkriptPotionEffect

java.lang.Object
org.skriptlang.skript.bukkit.potion.util.SkriptPotionEffect
All Implemented Interfaces:
YggdrasilSerializable, YggdrasilSerializable.YggdrasilExtendedSerializable, Cloneable

public class SkriptPotionEffect extends Object implements Cloneable, YggdrasilSerializable.YggdrasilExtendedSerializable
A wrapper class for passing around a modifiable PotionEffect.
  • Constructor Details

    • SkriptPotionEffect

      @Internal public SkriptPotionEffect()
      Internal usage only for serialization.
  • Method Details

    • fromType

      public static SkriptPotionEffect fromType(org.bukkit.potion.PotionEffectType potionEffectType)
      Constructs a SkriptPotionEffect from a Bukkit PotionEffectType.
      Parameters:
      potionEffectType - The type of effect for this potion effect.
      Returns:
      A potion effect with potionEffectType() as potionEffectType. Other properties hold their default values.
      See Also:
    • fromBukkitEffect

      public static SkriptPotionEffect fromBukkitEffect(org.bukkit.potion.PotionEffect potionEffect)
      Constructs a SkriptPotionEffect from a Bukkit PotionEffect.
      Parameters:
      potionEffect - The potion effect to obtain properties from.
      Returns:
      A potion effect whose properties are set from potionEffect.
      See Also:
    • fromBukkitEffect

      public static SkriptPotionEffect fromBukkitEffect(org.bukkit.potion.PotionEffect potionEffect, PotionEffectProvider<?> source)
      Constructs a SkriptPotionEffect from a Bukkit PotionEffect and source entity. source is expected to currently be affected by potionEffect. When changes are made to this potion effect, they will be reflected on source.
      Parameters:
      potionEffect - The potion effect to obtain properties from.
      source - A potion effect provider that should mirror the changes to this potion effect.
      Returns:
      A potion effect whose properties are set from potionEffect.
      See Also:
    • potionEffectType

      public org.bukkit.potion.PotionEffectType potionEffectType()
      Returns:
      The type of potion effect.
      See Also:
      • PotionEffect.getType()
    • potionEffectType

      @Contract("_ -> this") public SkriptPotionEffect potionEffectType(org.bukkit.potion.PotionEffectType potionEffectType)
      Updates the type of this potion effect.
      Parameters:
      potionEffectType - The new type of this potion effect.
      Returns:
      This potion effect.
    • infinite

      public boolean infinite()
      Returns:
      Whether this potion effect is infinite.
      See Also:
      • PotionEffect.isInfinite()
    • infinite

      @Contract("_ -> this") public SkriptPotionEffect infinite(boolean infinite)
      Updates whether this potion effect is infinite. This is a helper method that simply overrides duration() with the correct value.
      Parameters:
      infinite - Whether this potion effect should be infinite.
      Returns:
      This potion effect.
    • duration

      public int duration()
      Returns:
      The duration of this potion effect. Will be PotionEffect.INFINITE_DURATION if this effect is infinite().
      See Also:
      • PotionEffect.getDuration()
    • duration

      @Contract("_ -> this") public SkriptPotionEffect duration(int duration)
      Updates the duration of this potion effect.
      Parameters:
      duration - The new duration of this potion effect.
      Returns:
      This potion effect.
    • amplifier

      public int amplifier()
      Returns:
      The amplifier of this potion effect.
      See Also:
      • PotionEffect.getAmplifier()
    • amplifier

      @Contract("_ -> this") public SkriptPotionEffect amplifier(int amplifier)
      Updates the amplifier of this potion effect.
      Parameters:
      amplifier - The new amplifier of this potion effect.
      Returns:
      This potion effect.
    • ambient

      public boolean ambient()
      Returns:
      Whether this potion effect is ambient.
      See Also:
      • PotionEffect.isAmbient()
    • ambient

      @Contract("_ -> this") public SkriptPotionEffect ambient(boolean ambient)
      Updates whether this potion effect is ambient.
      Parameters:
      ambient - Whether this potion effect should be ambient.
      Returns:
      This potion effect.
    • particles

      public boolean particles()
      Returns:
      Whether this potion effect has particles.
      See Also:
      • PotionEffect.hasParticles()
    • particles

      @Contract("_ -> this") public SkriptPotionEffect particles(boolean particles)
      Updates whether this potion effect has particles.
      Parameters:
      particles - Whether this potion effect should have particles.
      Returns:
      This potion effect.
    • icon

      public boolean icon()
      Returns:
      Whether this potion effect has an icon.
      See Also:
      • PotionEffect.hasIcon()
    • icon

      @Contract("_ -> this") public SkriptPotionEffect icon(boolean icon)
      Updates whether this potion effect has an icon.
      Parameters:
      icon - Whether this potion effect should have an icon.
      Returns:
      This potion effect.
    • asBukkitPotionEffect

      public org.bukkit.potion.PotionEffect asBukkitPotionEffect()
      Constructs a Bukkit PotionEffect from this potion effect.
      Returns:
      A Bukkit PotionEffect representing the values of this potion effect. Note that the returned value may be the same across multiple calls, assuming that this potion effect's values have not changed.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(int flags)
      Parameters:
      flags - Currently unused.
      Returns:
      A human-readable string representation of this potion effect.
      See Also:
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • matchesQualities

      public boolean matchesQualities(org.bukkit.potion.PotionEffect potionEffect)
      Determines whether a potion effect has (at least) all the qualities of this potion effect.
      Parameters:
      potionEffect - The potion effect whose qualities will be checked.
      Returns:
      Whether potionEffect has all the qualities of this potion effect. Note that potionEffect may have additional qualities.
    • serialize

      public Fields serialize()
      Description copied from interface: YggdrasilSerializable.YggdrasilExtendedSerializable
      Serialises this object. Only fields contained in the returned Fields object will be written to stream.

      You can use return new Fields(this); to emulate the default behaviour.

      Specified by:
      serialize in interface YggdrasilSerializable.YggdrasilExtendedSerializable
      Returns:
      A Fields object containing all fields that should be written to stream
    • deserialize

      public void deserialize(@NotNull @NotNull Fields fields) throws StreamCorruptedException
      Description copied from interface: YggdrasilSerializable.YggdrasilExtendedSerializable
      Deserializes this object. No fields have been set when this method is called, use fields.setFields(this, yggdrasil) to set all compatible non-transient and non-static fields (and call incompatible/missing field handlers if applicable – this implies that errors will be thrown if the fields object is invalid).

      You can use fields.setFields(this); to emulate the default behaviour.

      Specified by:
      deserialize in interface YggdrasilSerializable.YggdrasilExtendedSerializable
      Parameters:
      fields - A Fields object containing all fields read from stream
      Throws:
      StreamCorruptedException - If the Fields object is invalid, i.e. was not written by YggdrasilSerializable.YggdrasilExtendedSerializable.serialize() or Yggdrasil's default serialisation.
    • clone

      public SkriptPotionEffect clone()
      Overrides:
      clone in class Object
    • isChangeable

      public static boolean isChangeable(Expression<? extends SkriptPotionEffect> expression)
      Checks whether the potion effects represented by an expression can be modified. For example, hidden potion effects cannot be modified.
      Parameters:
      expression - The expression to check.
      Returns:
      Whether the potion effects represented by expression can be modified. Logs an error if false.