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.-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.njol.yggdrasil.YggdrasilSerializable
YggdrasilSerializable.YggdrasilExtendedSerializable, YggdrasilSerializable.YggdrasilRobustEnum, YggdrasilSerializable.YggdrasilRobustSerializable -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanambient()ambient(boolean ambient) Updates whether this potion effect is ambient.intamplifier(int amplifier) Updates the amplifier of this potion effect.org.bukkit.potion.PotionEffectConstructs a BukkitPotionEffectfrom this potion effect.clone()voiddeserialize(@NotNull Fields fields) Deserializes this object.intduration()duration(int duration) Updates the duration of this potion effect.booleanstatic SkriptPotionEffectfromBukkitEffect(org.bukkit.potion.PotionEffect potionEffect) Constructs a SkriptPotionEffect from a Bukkit PotionEffect.static SkriptPotionEffectfromBukkitEffect(org.bukkit.potion.PotionEffect potionEffect, ItemType source) Constructs a SkriptPotionEffect from a Bukkit PotionEffect and source item.static SkriptPotionEffectfromBukkitEffect(org.bukkit.potion.PotionEffect potionEffect, org.bukkit.entity.LivingEntity source) Constructs a SkriptPotionEffect from a Bukkit PotionEffect and source entity.static SkriptPotionEffectfromType(org.bukkit.potion.PotionEffectType potionEffectType) Constructs a SkriptPotionEffect from a Bukkit PotionEffectType.booleanicon()icon(boolean icon) Updates whether this potion effect has an icon.booleaninfinite()infinite(boolean infinite) Updates whether this potion effect is infinite.static booleanisChangeable(Expression<? extends SkriptPotionEffect> expression) Checks whether the potion effects represented by an expression can be modified.booleanmatchesQualities(org.bukkit.potion.PotionEffect potionEffect) Determines whether a potion effect has (at least) all the qualities of this potion effect.booleanparticles(boolean particles) Updates whether this potion effect has particles.org.bukkit.potion.PotionEffectTypepotionEffectType(org.bukkit.potion.PotionEffectType potionEffectType) Updates the type of this potion effect.Serialises this object.toString()toString(int flags)
-
Constructor Details
-
SkriptPotionEffect
@Internal public SkriptPotionEffect()Internal usage only for serialization.
-
-
Method Details
-
fromType
Constructs a SkriptPotionEffect from a Bukkit PotionEffectType.- Parameters:
potionEffectType- The type of effect for this potion effect.- Returns:
- A potion effect with
potionEffectType()aspotionEffectType. Other properties hold their default values. - See Also:
-
fromBukkitEffect
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, org.bukkit.entity.LivingEntity source) Constructs a SkriptPotionEffect from a Bukkit PotionEffect and source entity.sourceis expected to currently be affected bypotionEffect. When changes are made to this potion effect, they will be reflected onsource.- Parameters:
potionEffect- The potion effect to obtain properties from.source- An entity that should mirror the changes to this potion effect.- Returns:
- A potion effect whose properties are set from
potionEffect. - See Also:
-
fromBukkitEffect
public static SkriptPotionEffect fromBukkitEffect(org.bukkit.potion.PotionEffect potionEffect, ItemType source) Constructs a SkriptPotionEffect from a Bukkit PotionEffect and source item.sourceis expected to be an item (potion, stew, etc.) whose meta containspotionEffect. When changes are made to this potion effect, they will be reflected onsource.- Parameters:
potionEffect- The potion effect to obtain properties from.source- An item 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:
-
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:
-
infinite
Updates whether this potion effect is infinite. This is a helper method that simply overridesduration()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_DURATIONif this effect isinfinite(). - See Also:
-
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:
-
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:
-
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:
-
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:
-
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 BukkitPotionEffectfrom 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
-
toString
- Parameters:
flags- Currently unused.- Returns:
- A human-readable string representation of this potion effect.
- See Also:
-
equals
-
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
potionEffecthas all the qualities of this potion effect. Note thatpotionEffectmay have additional qualities.
-
serialize
Description copied from interface:YggdrasilSerializable.YggdrasilExtendedSerializableSerialises 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:
serializein interfaceYggdrasilSerializable.YggdrasilExtendedSerializable- Returns:
- A Fields object containing all fields that should be written to stream
-
deserialize
Description copied from interface:YggdrasilSerializable.YggdrasilExtendedSerializableDeserializes 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:
deserializein interfaceYggdrasilSerializable.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 byYggdrasilSerializable.YggdrasilExtendedSerializable.serialize()or Yggdrasil's default serialisation.
-
clone
-
isChangeable
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
expressioncan be modified. Logs an error iffalse.
-