Module: command_state
Overview
This module allows defining a state
using predicate commands
.
Using this defined state
, you can:
-
Define commands to be executed when a player
enters
orleaves
thisstate
. -
Check whether a player is currently in the
state
. -
Display
placeholders
relevant to thestate
.
Color Boxes
◉ Define a state
using predicate commands
.
A state
is composed by predicate commands
.
You can define a state
called has-iron-and-gold
, with the following predicate commands
:
-
has-item? %player:name% minecraft:iron_ingot 16
-
has-item? %player:name% minecraft:gold_ingot 8
◉ Integrate with luckperms
's temporary permission
.
Assign a temporary permission
using /lp group default permission settemp fuji.permission.fly true 10s
Then define a state
to check whether a player has specified temporary permission
.
This state
can be called can-use-fly-command
with the following predicate commands
:
has-perm? %player:name% fuji.permission.fly
Last, you can define commands to be executed
when a player leave this state
.
For example, define commands to turn off the flying
while the player leaves
the state
.
◉ Check the value of a state
of a player.
Issue: /command-state info Steve
Besides that, the /is-in-state? <player> <state-id>
can be used as a predicate command
.
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:
command-state-data.json
- File Content:
Click to see the default
content...
{
"player_states_map": {}
}
- File Name:
config.json
- File Content:
Click to see the default
content...
{
"state_descriptors": [
{
"enable": true,
"id": "is-in-overworld",
"definition": {
"predicate_commands": [
"is-in-world? %player:name% minecraft:overworld"
]
},
"update_interval_seconds": 3,
"events": {
"on_enter_this_state_commands": [
"send-message %player:name% <green>You entered the overworld dimension."
],
"on_leave_this_state_commands": [
"send-message %player:name% <green>You left the overworld dimension."
]
}
},
{
"enable": true,
"id": "has-iron-and-gold",
"definition": {
"predicate_commands": [
"has-item? %player:name% minecraft:iron_ingot 16",
"has-item? %player:name% minecraft:gold_ingot 8"
]
},
"update_interval_seconds": 3,
"events": {
"on_enter_this_state_commands": [
"send-message %player:name% <green>You have `iron_ingot x 16` and `gold_ingot x 8`."
],
"on_leave_this_state_commands": [
"send-message %player:name% <green>You don't have `iron_ingot x 16` and `gold_ingot x 8`."
]
}
},
{
"enable": true,
"id": "can-use-fly-command",
"definition": {
"predicate_commands": [
"has-perm? %player:name% fuji.permission.fly"
]
},
"update_interval_seconds": 3,
"events": {
"on_enter_this_state_commands": [
"send-message %player:name% <green>You have gained access to `/fly` command."
],
"on_leave_this_state_commands": [
"send-message %player:name% <red>You temporary `/fly` command access has expired.",
"run as fake-op %player:name% fly false"
]
}
}
]
}
Jobs
-
Job Name:
ConfigurationHandlerWriteStorageJob
-
Document: This
job
is used towrite data
frommemory
intostorage
.NOTE: If you modify the
file
indisk
, then you need to issue/fuji reload
as soon as possible.NOTE: The
disk
will beoverridden
whenfire
this job.
-
Job Name:
CommandStateAutoUpdaterJob
-
Document: This
job
is used tocheck
andupdate
the value of all the definedstates
for all online players.When fired, its effect is equivalent to running the
/command-state update-all
command.
Commands
-
Command Syntax:
/command-state info <ServerPlayerEntity player>
-
Document: Display the value of all
states
of the specified player. -
Can be executed by console:
false
-
Required Level Permission:
4
-
Required String Permission:
null
-
Command Syntax:
/command-state list
-
Document: List all defined
states
. -
Can be executed by console:
true
-
Required Level Permission:
4
-
Required String Permission:
null
-
Command Syntax:
/command-state update-all
-
Document: Update all defined
states
for online players. -
Can be executed by console:
true
-
Required Level Permission:
4
-
Required String Permission:
null
-
Command Syntax:
/command-state update <StateDescriptor state>
-
Document: Update the specified
state
for online players. -
Can be executed by console:
true
-
Required Level Permission:
4
-
Required String Permission:
null
-
Command Syntax:
/is-in-state? <ServerPlayerEntity player> <StateDescriptor state>
-
Document: Returns whether the specified
state
value for the player is currentlytrue
. -
Can be executed by console:
true
-
Required Level Permission:
4
-
Required String Permission:
null
Placeholders
-
Placeholder Name:
fuji:is_in_state
-
Document: Returns the value of specified
state
of the player.Example:
%fuji:is_in_state is-in-overworld%
Argument Types
- Argument Type Name:
[state-id]
- Argument Type Class:
[StateDescriptor]