Class 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
      @NotNull java.lang.String key
      The key that "owns" this cooldown (example: a player's UUID)
      @NotNull java.lang.String type
      A string indicating the type of cooldown (examples: command.play, use_ability, etc...)
    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(@Nullable java.lang.Object other)
      Checks if the given object is equal to this cooldown
      It is equal if the key and type are the same
      long getRemaining()
      A long of the time remaining on the cooldown
      int hashCode()
      Returns the hash code of this cooldown
      It is the sum of the hash codes of the type and key
      boolean isOnCooldown()
      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 isOnCooldownStop()
      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 stop()
      Stops the cooldown
      • Methods inherited from class xyz.srnyx.javautilities.parents.Stringable

        toString, toString
      • Methods inherited from class java.lang.Object

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

      • type

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

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

      • AnnoyingCooldown

        public AnnoyingCooldown​(@NotNull
                                @NotNull CooldownManager manager,
                                @NotNull
                                @NotNull java.lang.Object type,
                                @NotNull
                                @NotNull java.lang.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 java.lang.Object type,
                                @NotNull
                                @NotNull java.lang.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 Detail

      • 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 java.lang.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 java.lang.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 java.lang.Object
        Returns:
        the hash code of this cooldown