-
Notifications
You must be signed in to change notification settings - Fork 0
CooldownFuture
David edited this page May 29, 2025
·
3 revisions
Before creating a Cooldown using the builder approach, you have to understand what a future is: An action that happens in the future, and involves a player and his cooldown.
The builder accepts and executes the appropriate ones when the following events occur:
- A cooldown is over for a player.
- A player tries to do something he shouldn't while on cooldown.
Although the library supports offline players by woorking with UUIDs, almost all futures require online players.
Example: You want to notify a player when his chat cooldown is over without running into NullPointerException in case he's offline at that point.
Checking if the player is online is a boilerplate.
To counter this issue, the recommended way to create futures is through each platform's factory.
//Pro Tip: statically import everything from CooldownFutureFactory
Cooldown<Player> chatCooldown = cooldownFactory.newBuilder()
.whenOver(message(ChatColor.GREEN + "You may now speak again!"))
.build();
Cooldown<Player> rewardingCooldown = cooldownFactory.newBuilder()
.whenOver(ifOnline((player, unused) ->
{
player.sendMessage(ChatColor.GREEN + "Thanks for waiting!");
player.getInventory().addItem(new ItemStack(Material.DIAMOND));
}))
.build();