Package me.tamkungz.nilkit.util
Class CooldownTracker
java.lang.Object
me.tamkungz.nilkit.util.CooldownTracker
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclearAll()Clears all cooldowns (global and per-player).intRemoves expired per-player entries and returns the number removed.longlongReturns remaining global cooldown in milliseconds, never negative.longgetPlayerRemainingMs(String playerName) Returns remaining cooldown for a player in milliseconds, never negative.booleanReturns true if the global cooldown has expired.booleanisPlayerReady(String playerName) Returns true if the player's cooldown has expired.voidSets global cooldown to now + cooldownMs.voidmarkPlayerUsed(String playerName) Sets cooldown for a specific player.voidremovePlayer(String playerName) Removes cooldown tracking for a player.booleanChecks and applies global cooldown atomically.booleantryUsePlayer(String playerName) Checks and applies cooldown for a player atomically.
-
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
Returns true if the player's cooldown has expired. -
markPlayerUsed
Sets cooldown for a specific player. -
tryUsePlayer
Checks and applies cooldown for a player atomically. -
getPlayerRemainingMs
Returns remaining cooldown for a player in milliseconds, never negative. -
removePlayer
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()
-