Conditions

Basic functionalities

This option will add some conditions for this event. If the conditions are accomplished, then the default actions will be executed.

Every line of the conditions list refers to a condition that MUST be true. You can use all kind of variables, even PlaceholderAPI or ConditionalEvents variables. Use the variables previously show in the Event Types page or the ones in the Variables page.

For example, in this case a Player Attack event has 3 conditions. The victim must be another player AND the item used must be a Diamond Sword AND the name of this item should be "Super Sword":

conditions:
- '%victim% == PLAYER'
- '%item% == DIAMOND_SWORD'
- '%item_name% == Super Sword'

You can also use 'and' separator in the same line, to accomplish the same as above.

conditions:
- '%victim% == PLAYER and %item% == DIAMOND_SWORD and %item_name% == Super Sword'

You can also check for 'or' condition separator, meaning that a condition line will be approved if one of many conditions in the same line is accomplished. For example, in this Player Command event there is just one condition. The command should start with //calc OR start with //solve OR start with //eval:

conditions:
- '%command% startsWith //calc or %command% startsWith //solve or %command% startsWith //eval'

You can only use a condition separator of one type in the same line. Meaning you can't mix ORs and ANDs in one condition line.

Advanced functionalities

You can also compare two variables in one condition line.

conditions:
- '%item_name% !contains %player_name%'

Finally, you can even compare variables with math formulas. If you want to do so, remember to set the following option on the event: allow_math_formulas_in_conditions: true

conditions:
- '%command% equals /test-kills'
- '%statistic_player_kills% >= %statistic_deaths%*2'

conditions:
- '%player_x% == (%player_z%*3)-1000'

Type of Conditionals

For Text

  • equals, ==

  • !equals, !=

  • equalsIgnoreCase

  • !equalsIgnoreCase

  • startsWith

  • !startsWith

  • contains

  • !contains

  • endsWith

  • !endsWith

  • matches (For regex)

  • !matches (For regex)

For Numbers

  • equals, ==

  • !equals, !=

  • >=

  • <=

  • >

  • <

Execute Option

Sometimes you will want to execute different actions depending on which conditions the player accomplishes or not. For example:

example:
    type: player_join
    conditions:
    - '%vault_rank% equals admin execute actions1'
    - '%vault_rank% equals vip execute actions2'
    actions:
      default:
      - 'to_all: message: &a%player% &ejoined the game.'
      actions1:
      - 'to_all: message: &4&lADMIN &c%player% &ejoined the game.'
      actions2:
      - 'to_all: message: &b&lVIP &a%player% &ejoined the game.'

This event will check when a player joins the server. If the rank of the player is admin, then the actions from "actions1" will execute. The same will happen if the rank of the player is vip, this case "actions2" will execute. Finally, if no "execute" conditions are met, the default actions will be executed.

If an "execute" condition is not accomplished it will continue to the next condition. If no more conditions are defined below an "execute" condition, the default actions will be executed. You can create as many sets of actions you want.

AND Conditions on Execute Option

The 'and' condition is very useful in some cases when using the execute option. For example, let's think you want to do something similar as above, sending a message to the whole server when a player with certain rank joins the server. But this time, the player must also have a certain level:

example:
    type: player_join
    conditions:
    - '%vault_rank% equals admin execute actions1'
    - '%vault_rank% equals vip and %player_level% > 20 execute actions2'
    actions:
      default: []
      actions1:
      - 'to_all: message: &4&lADMIN &c%player% &ejoined the game.'
      actions2:
      - 'to_all: message: &b&lVIP &a%player% &ejoined the game.'

Parameters

On execute conditions you can add optional parameters that allows you to reduce the amount of action groups in some cases and reuse the same action group with different parameters.

For example, imagine we have the following event:

# This event will check when a player uses the /vip <player> command 
# and set the specified player to the vip rank. 
# An error will show when the player doesn't have permissions. Another
# error will show when the player doesn't use arguments.
vip_rank:
    type: player_command
    conditions:
    - "%main_command% == /vip"
    - "%player_has_permission_conditionalevents.admin% != yes execute error_action1"
    - "%args_length% < 1 execute error_action2"
    actions:
      default:
      - "cancel_event: true"
      - "player_command: lp user %arg_1% parent set vip"
      error_action1:
      - "cancel_event: true"
      - "centered_message: &c&m                    &r &c&lERROR! &c&m                    "
      - "centered_message:  "
      - "centered_message: &cYou don't have permissions"
      - "centered_message:  "
      - "centered_message: &c&m                                                    "
      - "playsound: BLOCK_NOTE_BLOCK_PLING;10;0.1"
      error_action2:
      - "cancel_event: true"
      - "centered_message: &c&m                    &r &c&lERROR! &c&m                    "
      - "centered_message:  "
      - "centered_message: &cYou must use &7/vip <player>"
      - "centered_message:  "
      - "centered_message: &c&m                                                    "
      - "playsound: BLOCK_NOTE_BLOCK_PLING;10;0.1"

As you can see, error_action1 and error_action2 action groups are very similar, the only difference is the error message. We can simplify this event by using just one error_action action group by using parameters.

Parameters are specified after the action group name on the execute option, using brackets { }.

execute error_action{%variable1%=Variable 1 value;%variable2%=Variable 2 value}

The idea is to create parameters as temporal variables that can be used in the action group. You can create multiple parameters by using ;. If we use parameters in the previous example, the result is this:

vip_rank:
    type: player_command
    conditions:
    - "%main_command% == /vip"
    - "%player_has_permission_conditionalevents.admin% != yes execute error_action{%error_message%=&cYou don't have permissions}"
    - "%args_length% < 1 execute error_action{%error_message%=&cYou must use &7/vip <player>}"
    actions:
      default:
      - "cancel_event: true"
      - "player_command: lp user %arg_1% parent set vip"
      error_action:
      - "cancel_event: true"
      - "centered_message: &c&m                    &r &c&lERROR! &c&m                    "
      - "centered_message:  "
      - "centered_message: %error_message%"
      - "centered_message:  "
      - "centered_message: &c&m                                                    "
      - "playsound: BLOCK_NOTE_BLOCK_PLING;10;0.1"

We use the %error_message% variable and assign a value in both conditions. Then, in the error_action we can use this variable wherever we want.

Examples

Here is a full config example of a player attack event:

example1:
    type: player_attack
    conditions:
    - '%victim% == PLAYER'
    - '%item% == DIAMOND_SWORD'
    - '%item_name% == Super Sword'
    - '%random_1_10% >= 8'
    actions:
      default:
      - 'message: &aYour diamond sword poison effect was activated!'
      - 'to_target: give_potion_effect: POISON;120;1'

In this case, the plugin will check when a player attacks another player with a diamond sword called "Super Sword". A random number will be generated. If this number equals 8 or is greater than 8, then a message will be sended to the player and the target player will be affected by a poison effect.

Last updated