Cooldowns

What is it?

Cooldown.java is a pretty easy way to make a delay before using a command/item etc. Cooldown.java provides quite a bit of flexibility. It also gives you the ability to specify what happens after the cooldown.

Cooldown will not save after restart.

How to use it

Declare Cooldown variable.

private Cooldown<Player> cooldown = new Cooldown<>();
// You also can use string, UUID and etc. for T arg.

Adding cooldown

// Just add cooldown
cooldown.addNewCooldown(player, cooldownTime); 

// Rewrite cooldown if exists
cooldown.addNewCooldown(player, cooldownTime, true); 

// Execute runnable after cooldown is complete.
cooldown.addNewCooldown(player, cooldownTime, new Runnable()); 

// Rewirite cooldown if exists and execute runnable after cooldown is complete.
cooldown.addNewCooldown(player, cooldownTime, new Runnable(), true); 

Removing and checking cooldowns

CooldownTask

CooldownTask class is a simple implementation of BukkitRunnable with some QOL improvements.

Example

And done.

So whats special in this class? Basicly you can change task ticks left and runnable when task is already running. Also you can get ticks left via getTicksLeft method. But Cooldown class is using BukkitRunnable class in his map, so you need to cast BukkitRunnable to CooldownTask class.

You also can change runnable when task is already running and calling that runnable either.

Using it

You can use CooldownTask class with or without Cooldown class. And this is a reason why methods in CooldownTask are named setTime and getTime.

Last updated

Was this helpful?