Skip to content

条件系统 ​

条件文件要写清的内容如下: 条件组有哪些字段, 能放哪几种条件条目, 条件表达式里可以用哪些变量

条件文件放在 conditions/*.yml. 你可以把条件组用在装备限制, 配方限制, 技能限制和其他模块的判断上. 注意, 默认条件示例里有一部分写着 enabled: false, 需要你按服务器需求手动打开

条件组字段 ​

字段类型默认值说明
enabledbooleantrue要不要启用这个条件组
source_idstring—条件来源或业务标识
condition.typestringall_of条件的组合方式
condition.required_countinteger1当 condition.type 为 at_least 或 exactly 时, 需要满足几条条件
condition.invalid_as_failurebooleantrue条件配置异常或解析失败时, 要不要当作不通过
condition.entrieslist[]条件条目列表

condition.type 完整枚举 ​

值说明
all_of全部条件都满足才通过
any_of任意一个条件满足就通过
at_least至少满足 required_count 个条件
exactly恰好满足 required_count 个条件
none_of全部条件都不满足才通过

条件条目类型 ​

类型说明
pdc_meta检查 payload 中 meta 字段的值
lore_regex用正则匹配物品 Lore
pdc_attribute检查 payload 中某个属性的数值
source_id检查 payload 的 source_id 是否匹配

pdc_meta 条目字段 ​

字段说明
typepdc_meta
key要检查的 meta key
condition比较表达式, 支持占位符和运算符

lore_regex 条目字段 ​

字段说明
typelore_regex
pattern正则表达式
require_match要不要要求匹配成功 (true 表示必须匹配到)

pdc_attribute 条目字段 ​

字段说明
typepdc_attribute
key属性 ID
condition比较表达式

source_id 条目字段 ​

字段说明
typesource_id
condition比较表达式, 检查 payload 的 source_id

条件表达式内置变量 ​

你在 condition 字段里可以用这些变量:

变量说明
%value%当前字段值 (pdc_meta 的 key 对应值, 或 pdc_attribute 的属性值).lore_regex 分支例外: 那里传入的是命中的整行 Lore, 不是捕获组, 因此 %value% <= %player_level% 这类数值比较不成立, 请改用 $1
$0, $1, $2...正则捕获组 (lore_regex 类型中可用). $0 为整个匹配, $1 起为各捕获组. lore_regex 下取数值请用这些变量
%source_meta_<key>%payload meta 中指定 key 的值
%source_attribute_<key>%payload attributes 中指定属性的值
%source_id%payload 的 source_id
%player_name%玩家名称
%player_level%玩家经验等级

NOTE

如果安装了 PlaceholderAPI, 所有 PAPI 占位符也可在条件表达式中使用

示例: PDC meta 条件 ​

yaml
enabled: true
source_id: forge
condition:
  type: all_of
  invalid_as_failure: true
  entries:
    - type: pdc_meta
      key: required_level
      condition: '%value% <= %player_level%'

示例: 属性值条件 ​

yaml
enabled: true
source_id: equipment_check
condition:
  type: all_of
  entries:
    - type: pdc_attribute
      key: physical_attack
      condition: '%value% >= 50'

示例: 来源匹配条件 ​

yaml
enabled: true
source_id: strengthen
condition:
  type: all_of
  entries:
    - type: source_id
      condition: '%source_id% == "strengthen"'

示例: Lore 正则条件 ​

yaml
enabled: true
source_id: legacy_weapon
condition:
  type: any_of
  invalid_as_failure: true
  entries:
    - type: lore_regex
      pattern: '.*武器等级: (\d+).*'
      require_match: true
      condition: '$1 >= 20'

示例: 至少满足 N 个条件 ​

yaml
enabled: true
source_id: multi_check
condition:
  type: at_least
  required_count: 2
  entries:
    - type: pdc_meta
      key: enchant_level
      condition: '%value% >= 3'
    - type: pdc_meta
      key: quality
      condition: '%value% == "epic"'
    - type: pdc_attribute
      key: physical_attack
      condition: '%value% >= 100'

内置条件文件 ​

默认生成的条件文件:

文件source_id说明
strengthen.ymlstrengthen强化来源, entries 为空, 无条件通过
forge.ymlforge锻造来源, 检查 required_level <= %player_level%
emakiitem.ymlemakiitem物品来源, 把 condition_expressions 的值当作表达式执行; require_match: false 表示该 key 不存在时跳过而不是失败
default_bind.ymlgem_bind绑定检查 bound_player == %player_name%. 默认禁用
default_equipment_level.ymlgem_equipment_level用 lore_regex 匹配装备等级需求并与 %player_level% 比较. 默认禁用

改完条件文件后先执行 /ea lint, 这样在重载前就能发现 schema 问题 (缺少 source_id, 不支持的 checks 字段, 非法条件类型, 缺少 key / pattern, 无效正则等)