Skip to content

变量、表达式与占位符上下文矩阵

本页依据 4.5.6 生产实现中的 parser、service、model 与 PlaceholderAPI expansion 整理,覆盖 CoreLib、Attribute、Strengthen、Skills、Item、Forge、Cooking、Gem、Level、Codex。

先区分四种同形语法

很多位置都写成 %key%,但它们不是同一套系统:

类型用途解析时机
表达式变量数值、布尔、随机配置计算ExpressionEngine 或模块自身解析器求值时
内部模板变量Action、名称、Lore、消息等文本替换对应模块构造文本或 ActionContext 时
PlaceholderAPI 占位符给计分板、菜单、聊天等外部插件读取PlaceholderAPI 请求时
运行时上下文伤害、玩法事件、技能调用等携带的数据 Map由消费该上下文的表达式、条件或模板读取

同名变量只在其明确作用域内有效。不能因为某个 PAPI 占位符存在,就假定同名短变量可用于模块公式。

总览

插件主要表达式上下文内部模板 / Action 上下文PlaceholderAPI
CoreLib调用方 Map、随机配置局部 variables玩家、阶段、循环与调用方动态键无自有扩展,仅负责最后转交 PAPI
Attribute伤害阶段、恢复、DamageContext伤害消息emakiattribute
Strengthen货币成本;效果值仅有限引用强化展示、成功/失败动作emakistrengthen
Skills技能参数、自定义变量、升级成本技能脚本文本、升级消息emakiskills
Item物品构建、EA 属性、修复成本物品动作、套装显示emakiitem
Forge材料 stat/EA 属性/容量随机值最终物品展示、结果动作emakiforge
Cooking营养 Action 数量表达式食谱奖励与营养消息emakicooking
Gem宝石 stat/EA 属性、成本、镶嵌率镶嵌/升级/提取结果emakigem
Level升级需求、来源经验、属性、成本等级操作与升级结果emakilevel
Codex无自有公式环境;使用 GameplayEvent 条件变量触发器与成就完成文本无自有扩展

CoreLib

通用 ExpressionEngine

变量由调用方 Map 注入,写法为 %name%。CoreLib 没有为所有公式自动注入一组全局业务变量。

  • 运算符:+-*/%^、括号。
  • 函数:ceilfloorroundlog10minmaxpow,以及运行时注册的 JavaScript 函数。
  • 最大表达式长度 256 字符,最大递归深度 10。
  • 禁止反引号、$、反斜杠。
  • 缺失变量、自引用、非数值变量、NaN 或无限结果会使详细求值失败;简化接口通常回退为 0
  • 随机配置自身的 variables 会覆盖外部同名变量;动态变量按实际 Map 迭代顺序求值,后项可引用已经解析的前项。

实现依据:ExpressionEngineExpressionRulesRandomExpressionEvaluatorBooleanExpressionEvaluator

ActionContext 内部变量

变量说明
%player%%player_name%玩家名称
%player_uuid%玩家 UUID
%player_world%世界名
%player_x%%player_y%%player_z%玩家坐标
%phase%当前动作阶段
%template_<key>%Action 模板 with.<key> 参数
%loop_id%%loop_key%%loop_index%循环标识、键与从 1 开始的索引
%loop_times%%loop_remaining%%loop_interval%循环总次数、剩余次数与 tick 间隔文本
<show_item>独立内联 token;仅在上下文存在 show_item 时替换

调用模块还可通过 ActionContext.placeholders() 注入任意小写键。attributes() 不会自动转成模板变量。

实现依据:PlaceholderRendererActionTemplateProcessorLoopActionServiceActionInlineTokenResolver

GameplayEvent 变量

事件变量
方块破坏 / 放置block_type
实体击杀 / 驯服entity_type
MythicMobs 击杀mythic_idmythic_level
合成 / 熔炉取出result_typeresult_amount
钓鱼fish_state
酿造完成potion_type

这些键来自真实 Bukkit 事件,并由 Level、Codex 等模块按事件类型消费。

PlaceholderAPI 边界

CoreLib 不注册自己的 PlaceholderAPI expansion。解析链先处理内部变量与内联 token,再在安装 PlaceholderAPI 且存在玩家上下文时转交外部解析。

Attribute

自定义伤害阶段 stages[].expression

CUSTOM 阶段使用表达式。

变量语义 / 单位
inputbase进入当前阶段的伤害点
flat固定属性聚合值
percent百分比点
chance触发概率,0..100
multiplier倍率属性的百分比点
roll当前判定随机值,0..100
crit是否触发,10
DamageContext 任意键调用方或伤害服务写入的运行时上下文

重要边界:实现先写入上述固定键,再合并 DamageContext。因此 DamageContext 中的同名键会覆盖固定键。ATTACKER / TARGET 来源先读属性快照,缺失时可回退到上下文同名数值;CONTEXT 来源只读取上下文。

实现依据:StageCalculatorDamageContextVariables

DamageContext 标准键

  • 实体:attackerattacker_nameattacker_typeattacker_uuidsourcesource_nametargettarget_nametarget_typetarget_uuid
  • 伤害类型:damage_typedamage_type_namedamage_type_id
  • 伤害数值:source_damageinput_damagebase_damagedamagefinal_damage
  • 原因:causecause_namecause_iddamage_causedamage_cause_namedamage_cause_id
  • 投射物:projectile_typeprojectile_uuid
  • 控制:allow_criticalallow_target_dodgecalculate_target_defense
  • 随机:damage_rolldamage_roll_flatdamage_roll_percentdamage_roll_chancedamage_roll_multiplier,范围 0..1
  • 闪避:dodge_chancedodge_rolldodged,概率/随机值范围 0..100
  • 摔落:fall_distancejump_boost_levelvanilla_fall_damagefall_damage_formula

键在 DamageContextVariables 中会规范化为小写 identifier。

恢复公式 recovery.expression

变量说明
inputbasedamagefinal_damage最终伤害点
flathealing_flat固定恢复点数
percenthealing_percent恢复百分比点
percent_amounthealing_percent_amount按伤害折算的恢复量
grosshealing_gross抗性前总恢复量
resistancehealing_resistance恢复抗性百分比点

恢复固定键在继承 DamageContext 后写入,因此会覆盖上下文同名键。默认结果为 gross * (1 - resistance / 100),随后应用最小/最大值并钳制为非负。

实现依据:DamageRecoveryCalculator

伤害消息模板

messageattacker_messagetarget_message 使用普通 %key% 文本替换。除上述实体、伤害类型、伤害数值与原因键外,还提供:

source_typesource_uuidcriticalcritical_textcritical_suffixrollattacker_healthattacker_max_healthtarget_healthtarget_max_healthdistance

健康值与距离只从 DamageContext 读取;未注入时显示为 0

实现依据:DamageMessageDispatcher

PlaceholderAPI:emakiattribute

  • %emakiattribute_<attribute_id>%
  • %emakiattribute_power%
  • %emakiattribute_resource_<id>_current%
  • %emakiattribute_resource_<id>_max%
  • %emakiattribute_resource_<id>_default%
  • %emakiattribute_resource_<id>_bonus%
  • %emakiattribute_resource_<id>_percent%
  • %emakiattribute_resource_<id>_regen%

资源解析会把第一个下划线前的文本视为资源 ID,因此资源 ID 建议不要包含下划线。

Strengthen

成功率

成功率不是 ExpressionEngine 公式。实际计算为目标星基础成功率,加上有效锻印等级乘每级加成,最后限制到 0..success_chance_cap

实现依据:ChanceCalculator

货币成本 cost_formula

变量说明
base_cost货币基础成本
star目标星级,即当前星级 + 1

公式结果必须有限且大于 0,然后四舍五入为整数成本;否则该成本项会被跳过。

效果值解析边界

stars.<n>.variableseffects[type=variables].variablesea_attributes 的生产实现只支持:

  • Number;
  • 数值字符串;
  • 整个值恰好为 %name% 的引用。

%star% * 2 这类算术文本不会进入 CoreLib ExpressionEngine,会回退为 0。初始固定变量只有 star,后续动态键能否引用前项取决于实际 Map 迭代顺序。

实现依据:StrengthenRecipe.resolveExpressionsStrengthenApiValues.evaluateNumber/evaluateMixed

展示与动作变量

展示提供动态 stat 键,以及 startempermax_tempertemper_color;属性行另有 idsignvalue

成功/失败 Action 提供:

operation_idstrengthen_operation_idstrengthen_recipe_idstrengthen_recipestrengthen_starstrengthen_temperstrengthen_show_itemstrengthen_result_slotstrengthen_max_starstrengthen_success_rateshow_itemstartemperdroppedprotectedwas_star

实现依据:StrengthenSnapshotBuilderStrengthenActionCoordinator

PlaceholderAPI:emakistrengthen

mainhand_starmainhand_tempermainhand_recipemainhand_eligiblemainhand_success_countmainhand_failure_countmainhand_max_starmainhand_success_ratemainhand_crack_level

Skills

技能参数与自定义变量

skill_parameters.*、升级等级 parameters.* 使用:

变量说明
leveltarget_levelmax_level技能等级上下文
current_levelresolveAtLevel 额外提供的当前等级
skill_idtrigger_id技能与触发器 ID
is_passive是否被动技能,1/0
player_level原版经验等级
player_healthplayer_max_healthBukkit 生命点
sneakinghas_target布尔量,1/0

技能自定义 variables 还可引用已经解析的参数和此前自定义变量。参数本身不会自动获得其他参数的求值结果,TriggerInvocation.extraVariables() 当前也未合并进这套解析环境。

实现依据:SkillParameterResolverSkillVariableResolver

升级成本与文本

升级货币 cost_formula 使用上述固定上下文,并额外提供 base_cost;调用时 trigger_id=upgrade。升级成功率来自静态成功率表,不是公式。

技能脚本文本可使用 levelskill_idtrigger_idhas_target,以及已解析参数和自定义动态键。升级消息提供 playerskill_idskilllevelcurrent_leveltarget_levelmax_levelsuccess_ratesuccess_rate_rawroman_level 和成本/结果动态键。

PlaceholderAPI:emakiskills

  • 全局:cast_modeglobal_cooldownunlocked_countslot_countlevel_total
  • 技能:level_<skill_id>cooldown_<skill_id>
  • 槽位:slot_<index>_skill|name|trigger|empty
  • 资源:resource_<id>_current|max|percent

冷却单位为秒,槽位使用从 0 开始的索引。

Item

物品构建变量

顶层 variableseffects[type=variables].variables 没有固定内置变量,从空 Map 按顺序解析。名称、Lore、结构化展示与原版 attribute modifier 可读取这些动态键。

ea_attributeseffects[type=ea_attribute].ea_attributes 使用独立的空上下文顺序解析,不继承顶层 variables。不要在 EA 属性表达式中引用顶层构建变量。

实现依据:EmakiItemDefinitionParserEmakiItemFactoryEmakiItemPdcWriter

修复成本

变量说明
max_damage最大耐久
damagecurrent_damagemissing_durability当前缺失耐久点
missing_ratio缺失比例,0..1
restore_amount本次恢复耐久点
restore_ratio恢复比例,0..1
base_cost货币基础成本

实现依据:ItemRepairService

动作、套装与 PlaceholderAPI

物品 Action:playeritem_iditem_triggeritem_name

套装上下文:item_idset_idpiece_idset_nameactiveactive_counttotaltotal_piecesactive_thresholds

emakiitem PAPI:held_idheld_nameheld_componentsheld_components_rawloaded_count,以及 held_component_has_<id>held_component_value_<id>held_component_json_<id>

Forge

材料数值上下文

  • capacity_costcapacity_bonus.value 可使用随机数值配置,但没有变量上下文;结果四舍五入为容量整数。
  • effects[type=variables].variables 每种材料从空 Map 开始,后项可引用当前材料此前 stat 动态键。
  • effects[type=ea_attribute].ea_attributes 使用另一套独立空 Map,不继承 stat 变量。

未发现独立的锻造成功率、品质概率或货币成本 ExpressionEngine 公式。

展示与动作

最终名称/Lore 提供所有最终 stat 动态键,以及 qualityquality_namequality_multipliermultiplier

结果 Action 提供:forge_recipe_idforge_recipe_nameforge_source_item_nameforge_result_item_nameforge_qualityforge_multiplierforge_multiplier_rawforge_error_keyforge_failure_reasonforge_show_itemshow_item

实现依据:ForgeMaterialForgeStatContributionBuilderForgeResultPostProcessorForgeActionCoordinator

PlaceholderAPI:emakiforge

recipe_countcraft_count_<recipe_id>has_crafted_<recipe_id>total_craftslast_craftedguarantee_<key>

Cooking

表达式与内部变量

食谱生产链未发现通用 ExpressionEngine 公式。营养操作 Action 的 amount 可写表达式,变量来自当前 ActionContext 中能够转换为数字的 placeholder 与 attribute 动态键;没有额外固定变量。单位为营养点,异常回退为 0

食谱奖励 Action:recipe_idrecipe_namestation_typecooking_recipe_idcooking_recipe_namecooking_station_typecooking_outcome

营养消息:动态 nutrition_<type>nutrition_<type>_maxnutrition_<type>_min,以及 nutrition_typenutrition_valuenutrition_thresholdnutrition_combo_countnutrition_combo_required

实现依据:NutritionOperationActionRunRecipeRewardActionNutritionService

PlaceholderAPI:emakicooking

  • 配方数:recipe_countrecipe_count_<station_type>
  • 营养:nutrition_<type>nutrition_<type>_max|minnutrition_combo_count_<rule_id>
  • 工位:station_[<type>_]type|type_name|world|x|y|z|location|block|heat_block|burning|burning_seconds|heat|moisture|steam|input|input_source|input_amount|ingredient_count|recipe|recipe_id|progress|progress_target|progress_percent|completed|fluid|fluid_amount|player

fluid_amount 单位为 ml,burning_seconds 单位为秒。

Gem

宝石数值与成本

入口变量
宝石 variables / ea_attributeslevel,以及此前解析的同类动态键
共鸣 EA 属性无固定初始键,仅此前共鸣属性键
inlay_success.rate_formuladefault_chancelevel_chanceconfigured_chancelevel
镶嵌/提取/升级 cost_formulalevelcurrent_leveltarget_levelbase_cost

镶嵌率单位是百分比点,结果限制到 0..100。升级成功率来自静态等级成功率表,不是公式。成本固定 amount >= 0 时优先固定值,否则公式结果钳制非负。

实现依据:GemDefinitionGemResonanceLoaderGemInlayServiceGemExtractServiceGemUpgradeService

操作变量与 PlaceholderAPI

升级、镶嵌、提取链按场景提供 playergem_idgemlevelcurrent_leveltarget_levelsuccess_rateslot 等;宝石展示上下文另有 display_nameold_display_namegem_type 与各等级 stat 动态键。货币消息提供 providercurrencycurrency_idnamedisplay_namerequiredavailable;材料消息提供 itemmaterialdisplay_namerequiredavailable

emakigem PAPI:mainhand_opened_slotsmainhand_total_slotsmainhand_filled_slotsmainhand_item_definition_idmainhand_resonance_count,以及 mainhand_slot_<index>_gem|level|opened|type

Level

升级需求与成本

入口变量
升级经验需求 formulacurrent_leveltarget_levelmax_levelexptotal_exp
等级属性 attributes.<id>levelexptotal_exp
升级货币/材料成本target_leveltypebase_costbase_amount

固定 values.<target_level> 优先于需求公式。需求和货币结果钳制非负,材料数量四舍五入为非负整数。

来源经验

exp_formula 只获得当前 GameplayEvent 实际携带的键,不会自动追加统一玩家/等级变量:

  • 实体:entity_type
  • MythicMobs:mythic_idmythic_level
  • 方块:block_type
  • 合成/熔炉:result_typeresult_amount
  • 钓鱼:fish_state
  • 酿造:potion_type

Mythic drop 公式另有 amountdrop_amountmetadata_amountgenerationstick,并携带文本上下文 playertypedrop

Level operation Action 的 amount 与 Cooking 营养动作相同:只读取 ActionContext 中能转为数字的动态键,没有额外固定变量。

实现依据:RequirementServiceSourceExperienceServiceLevelGameplaySubscriberLevelAttributeBridgePlayerLevelServiceMythicLevelDropBridgeLevelOperationAction

PlaceholderAPI:emakilevel

  • 玩家:level_<type>exp_<type>total_exp_<type>totalexp_<type>total_<type>required_exp_<type>requiredexp_<type>required_<type>progress_<type>progress_percent_<type>
  • 排行:top_<type>_<rank>_name|level|total_exp|totalexp|total

排行榜 parser 按下划线分段,类型 ID 建议不要包含下划线。

Codex

Codex 不调用自己的 ExpressionEngine,也不注册 PlaceholderAPI expansion。

成就触发条件

触发条件使用 CoreLib ConditionEvaluator,变量来自 GameplayEvent,并额外提供 playerworld

block_typeentity_typemythic_idmythic_levelresult_typeresult_amountfish_statepotion_typeplayerworld

实际可用键取决于事件类型,不会同时全部存在。

触发器与完成文本

触发/action 行可读取当前事件键。成就完成上下文另有 advancement_idadvancement_nodeadvancement_titleadvancement_page

Codex 先执行本地 %key% 替换;有玩家且安装 PlaceholderAPI 时,再消费其他插件注册的外部占位符。

实现依据:CodexGameplaySubscriberCodexTriggerServiceAdvancementListener

配置时的通用检查清单

  1. 先确认当前位置属于公式、内部模板、PAPI 还是运行时上下文。
  2. 只使用本页对应作用域列出的固定键与该配置明确产生的动态键。
  3. 百分比可能使用 0..10..100;以对应模块说明为准。
  4. 动态键按 Map 顺序求值的模块,不要依赖未经验证的 YAML/Map 重排行为。
  5. Attribute、Level 等动态 ID parser 对下划线支持不一致,资源/排行 ID 优先使用不含下划线的形式。
  6. 若变量来自事件,必须为不同事件配置分别处理缺失键。