What is Command Cooldown?

Command Cooldown
A command cooldown is the easiest and the most effective way to do a command cooldown and it's because skript developers support it. With a command cooldown, players can wait a certain period of time before they can use a certain command again. This helps to prevent players from spamming commands and makes it less annoying for other players. Additionally, command cooldowns are easy to set up and manage.


When to Employ a Command Cooldown?
Let's say you want to add a cooldown to a simple command
command /cake:
    trigger:
        give a cake to the player



1. Establishing the Cooldown Duration
Incorporating cooldowns into commands is a breeze. Simply include the cooldown: expression before the trigger within the command, specifying the desired cooldown duration in terms of time units (e.g., ticks, seconds, minutes, hours, or days):
command /cake:
    cooldown: 1 hour
    trigger:
        give a cake to the player

As a result of adding cooldown: 1 hour to the command, you have successfully implemented a one-hour cooldown period. Players must now wait for this duration before using the command again.

2. Setting the cooldown period
To enhance the player experience, you can provide a custom message that informs players of the remaining cooldown time. This message is displayed when they attempt to use the command before the cooldown period expires:
command /cake:
    cooldown: 1 hour
    cooldown message: Wait %remaining time% to use this command again.
    trigger:
        give a cake to the player

With the addition of the cooldown message: expression, with the value Wait %remaining time% to use this command again , this will inform how much time remains for their cooldown. The %remaining time% will indicate how much time remains for the cooldown.

3. Cooldown Bypass and Canceling the Cooldown
You can allow certain players to bypass the cooldown by granting them specific permissions. To do this, use the cooldown bypass feature and create a permission, such as cooldown.bypass, for the exempted players:

command /cake:
    cooldown: 1 hour
    cooldown message: Wait %remaining time% to use this command again
    # Grant this permission to exempt specific players from the cooldown
   cooldown bypass: cooldown.bypass
    trigger:
        if the player has space for a cake:
            give a cake to the player
        else:
            send "Inventory is full."
            cancel the cooldown 
            #This cancels the cooldown, allowing players to use the command immediately

By employing the cooldown bypass and cancel the cooldown functionalities, you can meticulously customize the behavior of the command to align with the specific requirements of your server. This helps you avoid potential conflicts and ensure smooth server operations. Additionally, these features provide more flexibility and freedom when managing commands.

4. Cooldown Storage for Use in Other Commands
Cooldown storage is a valuable feature that allows you to access and manipulate the cooldown status in other commands or events. To use this functionality, define a variable where the cooldown information is stored. This variable can then be employed in other commands as needed:
command /cake:
    cooldown: 1 day
    # Store the cooldown in a variable for lasting control
    cooldown storage: {cooldown::%player's uuid%::cake}
    cooldown message: Wait %remaining time% to use this command again
    cooldown bypass: cooldown.bypass
    trigger:
        if the player has space for a cake:
            give a cake to the player
        else:
            send "Inventory is full."
            cancel the cooldown

The cooldown storage: feature, in this case, stores the cooldown information for the player with their UUID, allowing it to be referenced in other commands. This capability enhances the versatility of cooldown management on your server.


4.1 Utilizing Cooldown Storage in Other Commands
Here's an example of using cooldown storage in additional commands:
command /needMoreCakes:
    trigger:
        if {cooldown::%player's uuid%::cake} is set:
            delete {cooldown::%player's uuid%::cake}
            send "Cooldown resets"

In this example, the /needMoreCakes command checks if the cooldown for the /cake command, stored in the {cooldown::%player's uuid%::cake} If it is set in the variable, the command proceeds to delete this cooldown, allowing players to use the /cake command again.