Skip to content

Operators

Noogear edited this page Mar 9, 2026 · 2 revisions

操作符参考

所有操作符前均可加 ! 前缀取反(如 !null!contains!==)。

操作符矩阵

操作符 分类 说明
null 空值检测 检查变量是否为 null
instanceof 类型检测 检查类型并自动窄化
== 相等 相等比较
!= 相等 不等比较
> 数值 大于
>= 数值 大于等于
< 数值 小于
<= 数值 小于等于
between 数值 闭区间范围检查,value 为 [low, high]
starts_with 字符串 前缀匹配
ends_with 字符串 后缀匹配
matches 字符串 Java 正则全匹配
contains 成员 字符串包含 / 集合成员检查
in 成员 检查变量值是否在给定列表中

拼写纠错

引擎内置常见拼写错误的自动提示:

错误拼写 建议修正
startsWithstartswithstart_with starts_with
endsWithendswithend_with ends_with
matchregex matches
includeincludeshas contains
eqisequalequals ==
neneqnot !=
gt / lt / gte / lte > / < / >= / <=

instanceof 窄化

instanceof 检查成功后,变量类型自动窄化为目标类,后续节点可直接访问子类属性:

variables:
  entity: "entity"

flow:
  - check: entity
    op: "instanceof"
    value: "org.bukkit.entity.Player"

  # 窄化后可直接访问 Player 独有属性
  - action: "log"
    args: ["玩家名: {entity.playerName}"]

各操作符用法

null / !null

- check: target
  op: "null"     # 变量为 null 时通过

- check: target
  op: "!null"    # 变量不为 null 时通过

== / !=

- check: name
  op: "=="
  value: "sword"

- check: type
  op: "!="
  value: "BOW"

数值比较

- check: damage
  op: ">"
  value: 100

- check: hp
  op: "<="
  value: "{maxHp} * 0.3"

between

# 闭区间 [10, 50]
- check: damage
  op: "between"
  value: [10, 50]

starts_with / ends_with

- check: name
  op: "starts_with"
  value: "DIAMOND_"

- check: name
  op: "ends_with"
  value: "_SWORD"

matches

# Java 正则全匹配
- check: name
  op: "matches"
  value: ".*_SWORD$"

contains

# 字符串包含
- check: name
  op: "contains"
  value: "sword"

# 集合成员检查
- check: items
  op: "contains"
  value: "diamond"

in

# 检查变量值是否在给定列表中
- check: weaponType
  op: "in"
  value: ["DIAMOND_SWORD", "IRON_SWORD", "NETHERITE_SWORD"]

Clone this wiki locally