Skip to content

Repository files navigation

Command Items

This plugin aims to create items that trigger actions. For more information see below.

Compilation

  • Clone the repo
  • Depending on your system, run the correct gradle wrapper with the shadow task. This would look like this under a Unix-like system: ./gradlew shadow
  • Get the artifact from build/libs/CommandItems-<version>.jar

Usage

The configuration is based around so-called actions, which can trigger other actions or perform certain tasks.

This is the default configuration file, which contains a couple examples that should give you some insight into the functionality:

items:
fly:
item:
type: FEATHERname: "&a&lFlight token"lore: ["&1Click for 10 seconds of flight!", "&kRandom second line"]glow: trueconsumed: truecooldown: 20actions:
- { action: COMMAND, by: CONSOLE, command: "fly {player} on" }
- { action: MESSAGE, to: PLAYER, message: "&aFlight has been enabled!" }
- { action: REPEAT, from: 9, to: 1, increment: -1, delay: 20, period: 20, actions: [{ action: MESSAGE, to: PLAYER, value: "&a{i}s to go" }]}
- { action: WAIT, duration: 200, actions: [{ action: COMMAND, by: CONSOLE, command: "fly {player} off" },{ action: MESSAGE, to: PLAYER, message: "&cFlight has been disabled!" }]}helpstick:
item:
type: STICKname: "&a&lHelp Stick"lore: ["&1Click to send a help request to moderators!"]glow: trueconsumed: falsecooldown: 60actions:
- { action: MESSAGE, to: PERMISSION, perm: group.moderator, message: "&6{player} &arequested help!" }
- { action: MESSAGE, to: PLAYER, message: "&aModerators have been notified!" }xpparty:
item:
type: EXP_BOTTLEname: "&a&lEXP PARTY"consumed: trueactions:
- { action: REPEAT, period: 1, delay: 0, from: 0, to: 99, actions: [{ action: ITER, what: ONLINE_PLAYERS, actions: [{ action: CALC, a: "{iter_locY}", b: "4", op: ADD, target: "y", actions: [{ action: COMMAND, by: CONSOLE, command: "minecraft:summon minecraft:xp_bottle {iter_locX} {y} {iter_locZ}" }]}]}]}
- { action: MESSAGE, to: EVERYBODY, message: "&a&l{player} has started an XP party!" }

Variables

Variables are provided by actions and can be used within strings in sub-actions.

Generally available are

VariableDescription
nameThe name of the player that clicked the item
uuidThe UUID of the player that clicked the item

Available actions

COMMAND

This action can be used to execute commands.

ParameterDescriptionValid valuesDefault valueRequired
byDetermines who the command is executed byPLAYER,CONSOLE,PLAYER_PRIVILEGEDPLAYERfalse
commandThe command to executeAny command, without slashtrue
permThe permission that the player is temporarily given in PLAYER_PRIVILEGED modeAny permission*false

MESSAGE

This action can be used to send messages to players or the console:

ParameterDescriptionValid valuesDefault valueRequired
toThe message mode, more info belowPLAYER,CONSOLE,EVERYBODY,PERMISSIONPLAYERfalse
messageThe message to sendAnythingtrue
permIn PERMISSION mode, the permission required to receive the messageAny permission*if mode == PERMISSION
ModeDescription
PLAYERThe message is send to the player that clicked the item
CONSOLEThe message is printed to the console, useful for logging purposes
EVERYBODYThe message is broadcasted to every player
PERMISSIONThe message is broadcasted to every player that has a certain permission, specified by the perm parameter

CALC (Deprecated in favor of MATH_EXPR)

Perform some simple integer arithmetic

ParameterDescriptionValid valuesDefault valueRequired
opThe operation to performADD,SUB,MUL,DIVtrue
aOperand aIntegertrue
bOperand bIntegertrue
targetThe variable which the result will be stored inVariable nameyfalse
actionsSub actions which can use the result of this operationAn array/list of actionstrue

MATH_EXPR

Implements a small expression parser that can be used to evaluate mathematical expressions

ParameterDescriptionValid valuesDefault valueRequired
exprThe operation to performtrue
roundRound the output to int (1) or leave it as double (1.0)booleanfalsefalse
targetThe variable which the result will be stored inVariable nametrue
actionsSub actions which can use the result of this operationAn array/list of actionstrue

The expression parser can deal with c-style arithmetic expressions, a couple examples:

  • The gaussian pdf: 1/sqrt(2*pi*sigma^2)*exp(-(x-mu)^2/(2*sigma^2))
  • A gaussian random variable with mu = 5, sigma = 3: randn()*3 + 5
  • A uniformly distributed random value between 10 and 20: round(10 + 10 * rand())

You can play with the expression parser using the /cmdi calc command, where the gaussian pdf can be evaluated for sigma=5 and mu=0 at x=0 like this: /cmdi calc 1/sqrt(2*pi*sigma^2)*exp(-(x-mu)^2/(2*sigma^2)) mu=0 sigma=5 x=0.

Note: The /cmdi calc command cannot deal with spaces in the expression, because it uses spaces to delimit the expression of the context variables which are passed afterwards. This limitation is NOT present when specifying expressions in the command item configuration file.

Available variables:

  • pi, e
  • Numeric context variables

Available functions:

(Unless noted otherwise, trigonometric functions deal in radians, i.e. sin(pi/2) will evaluate to 1.0.)

FunctionDescription
sqrt(x)
sin(x)
asin(x)The inverse sin function
cos(x)
acos(x)The inverse cos function
tan(x)
atan(x)The inverse tan function
ceil(x)Always rounds up, i.e. ceil(0.1) -> 1.
floor(x)Always rounds down
abs(x)returns -x if x < 0 else x
exp(x)e^x
log(x)Natural logarithm
round(x)Round to nearest integer
min(x,y,...)Returns the smallest of n inputs
max(x,y,...)Returns the greatest of n inputs
fmod(x, y)x % y
sign(x)Returns the sign of x, or 0 for x = 0
rand()Uniform random number in [0,1) (0 inclusive, 1 exclusive)
randn()Standard normal distributed variable

Available operators are the usual:

  • +, -, *, /
  • x^y: x to the power y
  • x%y: Return the remainder of x divided by y

ITER

Iterate over things

ParameterDescriptionValid valuesDefault valueRequired
whatWhat to iterate overONLINE_PLAYERStrue
permA permission to filter players if what == ONLINE_PLAYERSAny permissiontrue
actionsSub actions which can use the result of this operationAn array/list of actionstrue
ONLINE_PLAYERS

When iterating over online players, the following variables are defined:

VariableDescription
iter_locXThe x-coordinate of the player
iter_locYThe y-coordinate of the player
iter_locZThe z-coordinate of the player
iter_nameThe name of the player
iter_displaynameThe display name of the player
iter_uuidThe uuid of the player
iter_healthThe health of the player
iter_levelThe XP level of the player
iter_foodThe food level of the player

REPEAT

The repeat action starts a timer that will repeatedly call its sub-actions until the iteration variable has reached its end. This is similar to what a for loop does in Java, where i is the iteration variable:

for (int i = start; increment > 0 ? i <= to : i >= to; i += increment)
actions();

Available parameters are:

ParameterDescriptionValid valuesDefault valueRequired
periodThe delay between two iterations in ticksInteger, >= 120false
delayThe delay before the first execution of the sub-actionsInteger, >= 020false
fromThe iteration start variable, inclusiveInteger0false
toThe iteration end variable, inclusiveInteger9false
incrementThe amount that the loop variable will be incremented with each iterationInteger1false
counterVarThe variable through which the loop counter will be made available to sub-actionsVariable nameifalse
actionsSub actions which will be executed with each loop cycleAn array/list of actionstrue

The loop counter is available through the variable named by counterVar.

WAIT

Wait executes a set of tasks with a certain delay.

ParameterDescriptionValid valuesDefault valueRequired
durationThe delay before the execution of the sub-actions, in ticksInteger, >= 020false
actionsSub actions which will be executed after the delayAn array/list of actionstrue

About

Assign commands to items

Topics

Resources

Stars

8 stars

Watchers

4 watching

Forks

Releases

Packages

Contributors

Languages