Class CooldownTracker

java.lang.Object
me.tamkungz.nilkit.util.CooldownTracker

public final class CooldownTracker extends Object
CooldownTracker — manages cooldowns for actions globally and per player.

The compound try-use operations are atomic, so multiple threads cannot consume the same ready cooldown window at the same time.

  • Constructor Details

    • CooldownTracker

      public CooldownTracker(long cooldownMs)
  • Method Details

    • isGlobalReady

      public boolean isGlobalReady()
      Returns true if the global cooldown has expired.
    • markGlobalUsed

      public void markGlobalUsed()
      Sets global cooldown to now + cooldownMs.
    • tryUseGlobal

      public boolean tryUseGlobal()
      Checks and applies global cooldown atomically.
    • getGlobalRemainingMs

      public long getGlobalRemainingMs()
      Returns remaining global cooldown in milliseconds, never negative.
    • isPlayerReady

      public boolean isPlayerReady(String playerName)
      Returns true if the player's cooldown has expired.
    • markPlayerUsed

      public void markPlayerUsed(String playerName)
      Sets cooldown for a specific player.
    • tryUsePlayer

      public boolean tryUsePlayer(String playerName)
      Checks and applies cooldown for a player atomically.
    • getPlayerRemainingMs

      public long getPlayerRemainingMs(String playerName)
      Returns remaining cooldown for a player in milliseconds, never negative.
    • removePlayer

      public void removePlayer(String playerName)
      Removes cooldown tracking for a player.
    • clearExpiredPlayers

      public int clearExpiredPlayers()
      Removes expired per-player entries and returns the number removed.
    • clearAll

      public void clearAll()
      Clears all cooldowns (global and per-player).
    • getCooldownMs

      public long getCooldownMs()