Module: command_cooldown
Overview
This module allows defining a cooldown after command execution.
Color Boxes
◉ There are 2 types of cooldown.
Unnamed Cooldown
You can use it to define a cooldown duration for a specified command. (It is tested and managed automatically)
A unnamed cooldown will not be persisted on the server shutdown.
Its typical use is to define a cooling duration for a specified command.
And a unnamed cooldown will be tested automatically when a player executes a command.
For example: define a 3 seconds cooling duration for /back command.
To define a unnamed cooldown, you need to modify the config file, and issue /fuji reload command to apply it.
NOTE: The console and players with level permission 4 can bypass the unnamed cooldown.
Named Cooldown
You have to use commands to create a named cooldown, and use commands to test it.
A named cooldown will be persisted on the server shutdown.
Its typical use is to define a named cooldown, and associate it with arbitrary command instance.
For example, you have to use /command-cooldown create to create a named cooldown.
Then, you have to use /command-cooldown test to test a named cooldown manually.
You have to specify the failure case commands and success case commands when test a named cooldown.
If the conditions defined by the named cooldown is satisfied, then it is a success case, else it is a failure case.
For success case, we will execute the success case command.
For failure case, we will execute the failure case command.
NOTE: If you only want to define a simple cooling duration for a specified command, just use unnamed cooldown.
◉ The command cooldown will NOT be applied if...
-
The command source is
the console. -
The command source is
admin(level permission >= 4)
◉ Create a named cooldown. (With 3 seconds cooldown duration.)
Issue: /command-cooldown create kitfood 3000
◉ Test a named cooldown with arbitrary command instance.
Issue: /command-cooldown test kitfood Alice say Used successfully once.
This command will test the specified named cooldown:
-
If the result is
the success case, then it will execute/say Used successfully once. -
If the result is
the failure case, then it will do nothing.
Issue: /command-cooldown test kitfood Alice --onFailed "say false" say true
This command will test the specified named cooldown:
-
If the result is
the success case, then it will execute/say true. -
If the result is
the failure case, then it will execute/say false.
TIP: You can insert %fuji:command_cooldown_left_time kitfood% placeholder to display the remaining duration.
TIP: To specify more than 1 command in the the success command or the failure command place, you can use chain module.
◉ Test a named cooldown with pre-defined command instance.
You can pre-define the success case commands and failure case commands in the config file.
And use /command-cooldown try-use kitfood Alice to test it.
This method is much more brief.
◉ Reset a named cooldown for a player.
Issue: /command-cooldown reset kitfood Alice
◉ Create a named cooldown. (With 15 seconds cooldown duration, and limit of number of use is 3)
Issue: /command-cooldown create kitfood 15000 --maxUses 3
◉ Create a global named cooldown.
By default, a named cooldown applies per-player.
A global named cooldown applies per-server.
Issue: /command-cooldown create kitfood 3000 --global true
◉ Make a non-persistent named cooldown.
By default, a named cooldown will be persisted on the storage.
However, you can create a non-persist named cooldown.
Issue: /command-cooldown create kitfood 999999999999 --persistent false
This cooldown says that, it can be used only once after each server re-start.
Configurations
The following JSON content is provided for reference only. It must NOT be copied directly into the configuration directory, as it does not represent valid JSON syntax.
- File Name:
config.json - File Content:
Click to see the default content...
{
"admin_players_can_bypass": true
/* The `unnamed cooldown` is applied `per-player`.
Define the `regex` expression to match the `target command`.
And the `cooldown ms` for that `target command`. */,
"unnamed_cooldown": {
"chunks.*": 60000,
"rtp.*": 60000,
"download.*": 120000
}
/* The `named cooldown` is created by `/command-cooldown create` command. */,
"named_cooldown": {
"list": {}
}
}
- File Name:
named-cooldown-data.json - File Content:
Click to see the default content...
{
"nodes": []
}
Jobs
-
Job Name:
ConfigurationHandlerWriteStorageJob -
Document: This
jobis used towrite datafrommemoryintostorage.NOTE: If you modify the
fileindisk, then you need to issue/fuji reloadas soon as possible.NOTE: The
diskwill beoverriddenwhenfirethis job.
Commands
-
Command Syntax:
/command-cooldown create <String name> <long cooldownDuration> [Integer maxUses] [Boolean persistent] [Boolean global] -
Document: Create a named-cooldown.
-
Can be executed by console:
true -
Required Level Permission:
4 -
Required String Permission:
null
-
Command Syntax:
/command-cooldown delete <NamedCooldownDescriptor namedCooldown> [Boolean confirm] -
Document: Delete a named-cooldown.
-
Can be executed by console:
true -
Required Level Permission:
4 -
Required String Permission:
null
-
Command Syntax:
/command-cooldown list -
Document: List all
unnamed-cooldownandnamed-cooldown. -
Can be executed by console:
true -
Required Level Permission:
4 -
Required String Permission:
null
-
Command Syntax:
/command-cooldown reset <NamedCooldownDescriptor namedCooldown> <ServerPlayerEntity player> -
Document: Reset
the last use timeof a named-cooldown for a player. -
Can be executed by console:
true -
Required Level Permission:
4 -
Required String Permission:
null
-
Command Syntax:
/command-cooldown test <NamedCooldownDescriptor namedCooldown> <ServerPlayerEntity player> [StringList onFailed] <GreedyCommandString onSuccess> -
Document: Test a named-cooldown with
arbitrary command instance, and executesuccess case commandorfailure case command. -
Can be executed by console:
true -
Required Level Permission:
4 -
Required String Permission:
null
-
Command Syntax:
/command-cooldown try-use <NamedCooldownDescriptor namedCooldown> <ServerPlayerEntity player> -
Document: Test a named-cooldown with
pre-defined command instance, and executesuccess case commandorfailure case command. -
Can be executed by console:
true -
Required Level Permission:
4 -
Required String Permission:
null
Placeholders
-
Placeholder Name:
fuji:command_cooldown_left_time -
Document: Returns the
remaining cooldown durationforspecified named cooldownin1d2h3m4sformat.For example, if you have a
named cooldownwhose name iskitfood.You can use:
%fuji:command_cooldown_left_time kitfood%
-
Placeholder Name:
fuji:command_cooldown_left_time_date -
Document: Returns the
next available dateforspecified named cooldown.For example, if you have a
named cooldownwhose name iskitfood.You can use:
%fuji:command_cooldown_left_time_date kitfood%
-
Placeholder Name:
fuji:command_cooldown_left_usage -
Document: Returns the
remaining available usesforspecified named cooldownin integer.For example, if you have a
named cooldownwhose name iskitfood.You can use:
%fuji:command_cooldown_left_usage kitfood%
Argument Types
- Argument Type Name:
[named-command-cooldown] - Argument Type Class:
[NamedCooldownDescriptor]