Skip to content

ConditionalCommands

Only execute a command if a condition is met.

ConditionalCommands is intended to be used when plugins have automatic commands that should only be executed if certain conditions are met. It is able to execute multiple commands, with customisable delays on each command.

This feature was modified by konsolas' ConditionalCommands project and is already built into Matrix. Original project: https://github.com/konsolas/ConditionalCommands

Usage

/coc <player> unless <condition> do <command>
/coc <player> if <condition> do <command>
/coc help

Conditions

Grammar of conditions:

<expression>::=<term>{<or><term>}
<term>::=<factor>{<and><factor>}
<factor>::=<comparison>|<not><factor>|(<expression>)
<comparison>::=<constant><comparator><constant>
<constant>::=floating point number or integer
<and>::='&'
<or>::='|'
<not>::='!'
<comparator>::='>'|'='|'<'

As shown above, only numbers can be compared, and placeholders can only consist of numbers. In case of multiple comparison operators in a group, i.e. 3>=<2, only the first operator will be used. Comparisons cannot include spaces. Inequality may be checked with !(value=value).

Examples:

/coc RERERE unless -ping->200 do kick RERERE
/coc RERERE if (-ping-<300&-ping->100)&-tps->15.0 do msg RERERE Your ping is between 300 and 100, and the TPS is greater than 15.

Examples used in the configuration file

yaml
## Jesus
# Check prevents the player from moving too too quickly in liquids, or walking on liquid.
jesus:
  # Enable this check?
  enable: true

  # Violations needed to cancel illegal movements (-1 = never cancel)
  cancel_vl: 15

  # Violation Thresholds
  # number_of_violations: '<command>'
  commands:
    10: 'coc %player% if -ping-<120&-tps->19.5 do matrix notify %player% tried to move illegally in liquid (Jesus)'
    25: 'coc %player% if -ping-<50&-tps->19.5&-time_online->10000 do matrix kick %player% Jesus/WaterSpeed/WaterFly Hacks'
    40: 'matrix kick %player% Jesus/WaterSpeed/WaterFly Hacks'

Placeholders

Placeholders are delimited by '-'. Since they're applied with a replace, errors will probably be detected during parsing if they are typed incorrectly.

  • ping - The latency of the tested player.
  • tps - Server TPS average over the last 2 seconds
  • time_online - Player's online time in milliseconds
  • uptime - Server uptime in ticks
  • player_count - Number of players on the server
  • perm:<permission> - 1.0 if the player has the permission, 0.0 otherwise. e.g. -perm:essentials.home-
  • vl:<check> - Matrix violation level of the given check (internal name). e.g. -vl:speed-
  • chance:<percentage>% - Will be 1.0 percentage% of the time. e.g. -chance:34.5%-

Multi command / delayed commands

In the 'do' clause of the statement, multiple commands can be executed at once, and selected commands can be delayed if desired. The command delimiter is /<delay>/, where the integer between / and / denotes the delay before the command should be executed in ticks. Here are some examples:

/coc konsolas if -vl:killaura->0 do /1200/ ban konsolas 1 minute delayed ban for killaura
/coc konsolas if -perm:some.permission-=1 do /0/ broadcast konsolas has some.permission! /0/ broadcast second broadcast! /20/ broadcast 1 second later!

Developer mode

The developer mode was removed in Matrix's built-in conditional commands system.

Made with ❤️ by RE