Cooldowns API
CooldownManagerstores expiration timestamps keyed byUUID -> cooldownId.CooldownStartEventfires before a cooldown is stored; it is cancellable.CooldownEndEventfires when a cooldown expires and gets removed.
Quick start (Java)
Keep one CooldownManager instance in your plugin:
public class MyPlugin extends JavaPlugin {
public final CooldownManager cooldowns = new CooldownManager();
@Override
public void onEnable() {
// Register listeners if you want start/end events
getServer().getPluginManager().registerEvents(new MyCooldownListener(), this);
}
public CooldownManager cooldowns() {
return cooldowns;
}
}
Command example with a 5s lockout:
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player player)) return true;
String id = "command.example";
if (cooldowns.isOnCooldown(player, id)) {
long remaining = cooldowns.getRemaining(player, id);
player.sendMessage("Wait " + CooldownManager.formatRemaining(remaining) + " before reusing.");
return true;
}
// Do work here
runAbility(player);
// Apply 5 seconds (5000 ms)
cooldowns.setCooldown(player, id, 5000L);
return true;
}
Events
CooldownStartEvent
- Fired when
setCooldown(...)is called (after computingendTimestamp). - Cancellable: call
event.setCancelled(true)to block applying the cooldown.
CooldownEndEvent
- Called when an expiration is detected and the entry is removed.
- Triggers on first read after expiry via
getRemaining(...)or when you manually invokecheckAndTriggerEnd(...).
Listener example:
public class MyCooldownListener implements Listener {
@EventHandler
public void onCooldownStart(CooldownStartEvent event) {
if (event.getCooldownId().equals("command.example") && event.getDurationMillis() > 20_000) {
event.setCancelled(true); // cap long cooldowns
}
}
@EventHandler
public void onCooldownEnd(CooldownEndEvent event) {
UUID playerId = event.getPlayerId();
// Notify or log
}
}
API reference (CooldownManager)
For more info check the Javadocs.