上一页:GUI动作与条件速查.md · 下一页:脚本入门.md 相关:自定义GUI.md · 配置文件.md · 经济API.md · 经济插件.md
💰 经济动作
本篇专讲 GUI 点击动作里的三个经济动作:give_money(给钱)、take_money(扣钱)、set_money(设置余额)。把 value 怎么写讲透,并覆盖 Vault / PlayerPoints / ExcellentEconomy 各后端的差异。
GUI 基础结构见 自定义GUI.md,经济系统的全局配置见 配置文件.md 的 economy 段。
🧩 三个动作
| 动作 type | 别名 | 作用 |
|---|---|---|
give_money | givemoney | 给玩家发放货币 |
take_money | takemoney,remove_money | 扣除玩家货币(先查余额,不足则不扣) |
set_money | setmoney | 直接把余额设为某值 |
yaml
click-actions:
reward:
type: give_money
value: "500"📝 value 完整语法
统一格式(EconomyActionParser):
[provider:][currency:]金额 [| 失败提示]拆开看四个部分:
| 部分 | 是否必填 | 说明 |
|---|---|---|
provider: | 选填 | 用哪个经济后端:vault / excellenteconomy / playerpoints / auto,别名 ee / pp |
currency: | 视后端而定 | 货币种类(仅 ExcellentEconomy 需要) |
金额 | 必填 | 数字,是各段中最后一个能转成数字的段 |
| 失败提示 | 选填 | 用 | 分隔,操作失败时显示给玩家的文本(支持 & 码) |
🔍 解析规则(照着推就不会错)
- 先用
|把「主体」和「失败提示」分开。 - 主体再用
:切段;金额永远是最后一个能转成数字的段。 - 前缀段怎么认:
- 一段前缀:若它是已知 provider(
vault/excellenteconomy/playerpoints/auto或别名ee/pp),就当 provider;否则当 currency。 - 两段前缀:
provider:currency。 - 没有前缀(纯数字):只有金额,provider/currency 用默认值。
- 一段前缀:若它是已知 provider(
📋 解析示例对照
| value 写法 | provider | currency | 金额 | 失败提示 |
|---|---|---|---|---|
100 | 默认 | 默认 | 100 | — |
money:100 | 默认 | money | 100 | — |
vault:50 | vault | — | 50 | — |
excellenteconomy:gold:100 | ee | gold | 100 | — |
100 | 余额不足 | 默认 | 默认 | 100 | 余额不足 |
excellenteconomy:money:50 | 金币不足 | ee | money | 50 | 金币不足 |
💡 注意
vault:50里vault被认成 provider,但money:100里money不是已知 provider,所以被当成 currency。这正是「一段前缀」的判定逻辑。
🔌 各后端差异(重点)
| 后端 | provider 写法 | currency 处理 |
|---|---|---|
| Vault | vault | 忽略 currency |
| PlayerPoints | playerpoints / pp | 忽略 currency |
| ExcellentEconomy | excellenteconomy / ee | 必须指定 currency,否则报 CURRENCY_REQUIRED |
- Vault / PlayerPoints:单货币系统,写不写
currency:都没用,会被忽略。直接vault:100、pp:100。 - ExcellentEconomy:多货币系统,必须写明是哪种货币,如
ee:gold:100。漏写 currency 会失败并报CURRENCY_REQUIRED。
🤖 auto 选源
provider 写 auto(或干脆不写 provider)时,由系统自动选择可用的经济后端。适合不确定服务器装了哪个经济插件、或希望配置可移植时使用。
yaml
value: "auto:100" # 自动选后端
value: "100" # 不写 provider 等同走默认/自动📋 大量写法示例
yaml
# —— 最简单:默认后端给 500 ——
reward:
type: give_money
value: "500"
# —— Vault:扣 100(currency 写了也被忽略)——
pay:
type: take_money
value: "vault:100"
# —— PlayerPoints:用别名 pp 给 50 点 ——
points:
type: give_money
value: "pp:50"
# —— ExcellentEconomy:必须带 currency ——
buy_gold:
type: take_money
value: "ee:gold:100"
# —— ExcellentEconomy 全写法 + 失败提示 ——
buy:
type: take_money
value: "excellenteconomy:money:50 | &c金币不足,无法购买"
# —— 只指定 currency,provider 走默认 ——
spend:
type: take_money
value: "money:200"
# —— set_money:把余额直接设为 0 ——
reset:
type: set_money
value: "0"
# —— auto 自动选源 + 失败提示 ——
gift:
type: give_money
value: "auto:1000 | &c发放失败,请联系管理员"💬 失败提示与默认消息
| 失败提示 是可选的;不写时各动作有内置默认消息。下面是各动作在不同情况下显示什么:
| 动作 | 情况 | 显示内容 |
|---|---|---|
give_money | 发放失败 | failMessage 或 &c发放货币失败 |
take_money | 余额不足 | 固定 &c余额不足(不用 failMessage) |
take_money | 扣除失败(余额够但操作失败) | failMessage 或 &c扣除货币失败 |
set_money | 设置失败 | failMessage 或 &c设置余额失败 |
| 全部 | value 格式错误 | &c经济动作格式错误 |
| 全部 | 经济系统不可用 | failMessage 或 &c经济系统不可用 |
⚠️ 关键点:
take_money在「余额不足」时显示的是固定的&c余额不足,你写的| 失败提示在这种情况下不会生效;只有在「余额够但实际扣除失败」时才会用到你的 failMessage。
🩺 常见错误与排查
| 现象 | 可能原因 | 解决 |
|---|---|---|
提示 &c经济动作格式错误 | value 写法不对(如金额段缺失、全是文字) | 对照上方语法表,确保有一个能转数字的段 |
提示 CURRENCY_REQUIRED | 用了 ExcellentEconomy 但没写 currency | 改成 ee:货币名:金额,如 ee:gold:100 |
提示 &c经济系统不可用 | 没装对应经济插件 / provider 名写错 | 装好插件,或用 auto,检查 provider 拼写 |
| 自定义失败提示不显示 | 是 take_money 余额不足的情况 | 该情况固定显示 &c余额不足,无法覆盖;其它失败才走 failMessage |
| currency 写了不起作用 | 后端是 Vault / PlayerPoints | 它们是单货币,currency 本就被忽略,属正常 |
| 金额被错认成 currency | 段顺序写反 | 金额必须能转数字;前缀按 provider:currency 排 |
🔌 provider 别名速记:
ee=excellenteconomy,pp=playerpoints。
📖 继续阅读
- ⚙️ 配置文件.md —
economy配置段(默认 provider、开关) - 🖼️ 自定义GUI.md — 经济动作所在的 GUI 结构
- 🔎 GUI动作与条件速查.md — 配合
money显隐条件做购买按钮 - 🧰 经济API.md — 开发者直接调经济接口
- 🔗 经济插件.md — 对接 Vault / PlayerPoints / ExcellentEconomy