Class AnnoyingCooldown

java.lang.Object
xyz.srnyx.javautilities.parents.Stringable
xyz.srnyx.annoyingapi.cooldown.AnnoyingCooldown

public class AnnoyingCooldown extends xyz.srnyx.javautilities.parents.Stringable
This class is used to create and manage cooldowns
All cooldowns are removed when the server is restarted! They're only stored in CooldownManager.cooldowns
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final @NotNull String
    The key that "owns" this cooldown (example: a player's UUID)
    final @NotNull String
    A string indicating the type of cooldown (examples: command.play, use_ability, etc...)
  • Constructor Summary

    Constructors
    Constructor
    Description
    AnnoyingCooldown(@NotNull AnnoyingPlugin plugin, @NotNull Object type, @NotNull String key)
    Creates a new cooldown with the given type, key, and duration
    AnnoyingCooldown(@NotNull CooldownManager manager, @NotNull Object type, @NotNull String key)
    Creates a new cooldown with the given type, key, and duration
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(@Nullable Object other)
    Checks if the given object is equal to this cooldown
    It is equal if the key and type are the same
    long
    A long of the time remaining on the cooldown
    int
    Returns the hash code of this cooldown
    It is the sum of the hash codes of the type and key
    boolean
    Checks if the cooldown is still going
    boolean
    isOnCooldownStart(long duration)
    Checks if the cooldown is still going
    If it isn't, it will start the cooldown
    boolean
    Checks if the cooldown is still going
    If it is, it will stop the cooldown
    void
    start(long duration)
    Starts the cooldown
    If the cooldown is already started, it will be restarted
    void
    Stops the cooldown

    Methods inherited from class xyz.srnyx.javautilities.parents.Stringable

    toString, toString, toString, toString, toString

    Methods inherited from class java.lang.Object

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

    • type

      @NotNull public final @NotNull String type
      A string indicating the type of cooldown (examples: command.play, use_ability, etc...)
    • key

      @NotNull public final @NotNull String key
      The key that "owns" this cooldown (example: a player's UUID)
  • Constructor Details

    • AnnoyingCooldown

      public AnnoyingCooldown(@NotNull @NotNull CooldownManager manager, @NotNull @NotNull Object type, @NotNull @NotNull String key)
      Creates a new cooldown with the given type, key, and duration
      Parameters:
      manager - manager
      type - type
      key - key
    • AnnoyingCooldown

      public AnnoyingCooldown(@NotNull @NotNull AnnoyingPlugin plugin, @NotNull @NotNull Object type, @NotNull @NotNull String key)
      Creates a new cooldown with the given type, key, and duration
      Parameters:
      plugin - the plugin that is creating the cooldown (used to get the manager)
      type - type
      key - key
  • Method Details

    • getRemaining

      public long getRemaining()
      A long of the time remaining on the cooldown
      Returns:
      amount of time left in the cooldown (in milliseconds)
      See Also:
      • DurationFormatter.formatDuration(long, String, boolean)
    • isOnCooldown

      public boolean isOnCooldown()
      Checks if the cooldown is still going
      Returns:
      whether the cooldown is still going
    • isOnCooldownStart

      public boolean isOnCooldownStart(long duration)
      Checks if the cooldown is still going
      If it isn't, it will start the cooldown
      Parameters:
      duration - the duration of the cooldown (in milliseconds)
      Returns:
      whether the cooldown was still going
    • isOnCooldownStop

      public boolean isOnCooldownStop()
      Checks if the cooldown is still going
      If it is, it will stop the cooldown
      Returns:
      whether the cooldown was still going
    • start

      public void start(long duration)
      Starts the cooldown
      If the cooldown is already started, it will be restarted
      Parameters:
      duration - the duration of the cooldown (in milliseconds)
    • stop

      public void stop()
      Stops the cooldown
    • equals

      public boolean equals(@Nullable @Nullable Object other)
      Checks if the given object is equal to this cooldown
      It is equal if the key and type are the same
      Overrides:
      equals in class Object
      Parameters:
      other - the object to compare to
      Returns:
      whether the object is equal to this cooldown
    • hashCode

      public int hashCode()
      Returns the hash code of this cooldown
      It is the sum of the hash codes of the type and key
      Overrides:
      hashCode in class Object
      Returns:
      the hash code of this cooldown