Cooldowns
Cooldown lets you track a cooldown for anything with a UUID, not just players.
Cooldown.createCooldown("mine_ability", 10) // 10 second cooldown
Cooldown.addCooldown("mine_ability", player.uniqueId)
if (Cooldown.isOnCooldown("mine_ability", player.uniqueId)) {
player.sendMessage("Still on cooldown!")
}
There are also some shortcuts on CommandSender to keep your code cleaner:
if (sender.withCooldown("mine_ability", 10)) {
// runs your logic and starts the cooldown, only if not already on cooldown
}
Expired cooldowns aren't removed on their own - they don't do anything, they just sit in memory. Call Cooldown.cleanup() whenever you want to clear them out, for example from a repeating task. To end one player's cooldown early, use Cooldown.removeCooldown(id, uuid).
If you only need a cooldown inside one class (anti-spam on a toggle, a pay command), CooldownMap is simpler - its entries expire by themselves, and you can wipe it with clear():
private val payCooldown = CooldownMap<UUID>(15, TimeUnit.SECONDS)
if (payCooldown.isOnCooldown(player.uniqueId)) return
payCooldown.add(player.uniqueId)