What is Date Cooldown?

Date Cooldown
Date cooldown allows you to create a cooldown for anything in Skript. This can be useful when you want to limit how often certain actions can be performed. Let's dive into the implementation details.
When to Employ a Date Cooldown?
In this case we want to create a 10 second cooldown so players don't spam the sonic boom.
on flight toggle:
    cancel event
    push the player horizontal forward at speed 5
    send "sonic boom!"


Date Cooldown Implementation
Before setting up the cooldown, it's essential to understand how the date cooldown syntax works. There are two options: %timespan% (ago|in the past|before [the] [date] %date%) and %timespan% (later|(from|after) [the] [date] %date%). These expressions allow you to work with time spans relative to a given date.

1. Setting up the Cooldown
Now, let's set up the cooldown. This will ensure that your events won't trigger too frequently.
Use the following commands to set up the cooldown for your specific event. You can choose different time spans for your needs.
Set the cooldown to a specific time from now:
    set {cooldown::%player's uuid%::event} to %timespan% from now

Exmaples:
    set {cooldown::%player's uuid%::event} to 10 seconds from now
    #You can also set it for a more extended period
    set {cooldown::%player's uuid%::event} to 2 hours from now

2. Checking the Cooldown
Checking the cooldown is now simplified. You only need to compare the cooldown timestamp with the current time.
Use one of the following if statements to check the cooldown:
If the cooldown timestamp is greater than the current time, it means the cooldown is still active, and you should cancel the event:

    if {cooldown::%player's uuid%::event} is greater than now:
    #Or, you can use the '>' symbol as a shorthand:
    if {cooldown::%player's uuid%::event} > now:

3. Applying the Cooldown to Your Event
Now, let's apply the cooldown to your specific event. This example assumes you want to apply the cooldown to a flight toggle event. Modify it as needed for your event.
Use this code to apply the cooldown to your event:

on event:
    # Check if the cooldown variable is set to a time after the current time
    if {cooldown::%player's uuid%::event} is greater than now:
        # Cancel the event since the cooldown is not yet over
        cancel event
        # Calculate the remaining cooldown time
        set {_waited} to difference between {cooldown::%player's uuid%::event} and now
        send "Try again in %{_waited}%"
    else:
        # Set the cooldown to 10 seconds from the current time
        set {cooldown::%player's uuid%::event} to 10 seconds from now

Exmaples:
on flight toggle:
    cancel event
    if {cooldown::%player's uuid%::flightToggle} is greater than now:
        set {_waited} to difference between {cooldown::%player's uuid%::flightToggle} and now
        send "Try again in %{_waited}%"
    else:
        set {cooldown::%player's uuid%::flightToggle} to 10 seconds from now
        push the player horizontal forward at speed 5
        send "sonic boom!"

In this approach, we check if the cooldown variable is set to a time that is after the current time. If it is, we provide the remaining cooldown time. Otherwise, we proceed with executing the event and update the cooldown timestamp to 10 seconds from the current time.

on consume:
    if now < {cooldown::%player's uuid%::diet}:
        cancel event
        send "You are on a diet"
    else:
        # Update the cooldown timestamp to 10 minutes from now
        set {cooldown::%player's uuid%::diet} to 10 minutes later

In this case, we check if the cooldown is still active. If it is, the event is canceled and a message is sent to the player. If the cooldown has passed, we update the cooldown timestamp to 10 minutes from the current time.