Class StatusEffect

java.lang.Object
io.github.thebusybiscuit.slimefun4.api.player.StatusEffect
All Implemented Interfaces:
net.kyori.adventure.key.Keyed, org.bukkit.Keyed

public class StatusEffect extends Object implements org.bukkit.Keyed
A very simple API that is meant for adding/getting/clearing custom status effects to/from players. The effects are stored via PersistentDataAPI and use NBT data that is saved across server restarts. You can specify a level for your status effect too.
Author:
TheBusyBiscuit
  • Constructor Summary

    Constructors
    Constructor
    Description
    StatusEffect(org.bukkit.NamespacedKey key)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(org.bukkit.entity.Player p, int level, int duration, TimeUnit unit)
    This applies this StatusEffect to the given Player.
    void
    add(org.bukkit.entity.Player p, int duration, TimeUnit unit)
    This applies this StatusEffect to the given Player.
    void
    addPermanent(org.bukkit.entity.Player p, int level)
    This applies this StatusEffect to the given Player.
    void
    clear(org.bukkit.entity.Player p)
    This will remove this StatusEffect from the given Player.
    org.bukkit.NamespacedKey
     
    getLevel(org.bukkit.entity.Player p)
    This method returns an OptionalInt describing the level of this status effect on that player.
    boolean
    isPresent(org.bukkit.entity.Player p)
    This will check whether this StatusEffect is currently applied to that Player.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.bukkit.Keyed

    key
  • Constructor Details

    • StatusEffect

      public StatusEffect(@Nonnull org.bukkit.NamespacedKey key)
  • Method Details

    • getKey

      @Nonnull public org.bukkit.NamespacedKey getKey()
      Specified by:
      getKey in interface org.bukkit.Keyed
    • add

      public void add(@Nonnull org.bukkit.entity.Player p, int duration, @Nonnull TimeUnit unit)
      This applies this StatusEffect to the given Player. You can specify a duration, this will reference add(Player, int, int, TimeUnit) with a level of 1.
      Parameters:
      p - The Player whom to apply the effect to
      duration - The duration of how long that status effect shall last
      unit - The TimeUnit for the given duration
    • add

      public void add(@Nonnull org.bukkit.entity.Player p, int level, int duration, @Nonnull TimeUnit unit)
      This applies this StatusEffect to the given Player.
      Parameters:
      p - The Player whom to apply the effect to
      level - The level of this effect
      duration - The duration of how long that status effect shall last
      unit - The TimeUnit for the given duration
    • addPermanent

      public void addPermanent(@Nonnull org.bukkit.entity.Player p, int level)
      This applies this StatusEffect to the given Player. This will apply it permanently, there is no duration.
      Parameters:
      p - The Player whom to apply the effect to
      level - The level of this effect
    • isPresent

      public boolean isPresent(@Nonnull org.bukkit.entity.Player p)
      This will check whether this StatusEffect is currently applied to that Player. If the effect has expired, it will automatically remove all associated NBT data of this effect.
      Parameters:
      p - The Player to check for
      Returns:
      Whether this StatusEffect is currently applied
    • getLevel

      @Nonnull public OptionalInt getLevel(@Nonnull org.bukkit.entity.Player p)
      This method returns an OptionalInt describing the level of this status effect on that player.
      Parameters:
      p - The Player to check for
      Returns:
      An OptionalInt that describes the result
    • clear

      public void clear(@Nonnull org.bukkit.entity.Player p)
      This will remove this StatusEffect from the given Player.
      Parameters:
      p - The Player to clear it from