Skip to content

Commit a46c0d1

Browse files
committed
Add economy reference guide
1 parent 666e8f1 commit a46c0d1

3 files changed

Lines changed: 272 additions & 0 deletions

File tree

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
---
2+
title: 货币字段参考
3+
description: Economy/currency.yml 的字段、动作语法和占位符说明。
4+
---
5+
6+
# 货币字段参考
7+
8+
这页只讲 `plugins/MatrixShop/Economy/currency.yml` 的字段规则。
9+
如果你想直接照抄配置,请看 [经济配置实战示例](./economy-examples)
10+
11+
## 文件结构
12+
13+
每个顶层 key 代表一个可引用的货币:
14+
15+
```yml
16+
vault:
17+
Mode: vault
18+
Display-Name: "金币"
19+
Symbol: "$"
20+
Decimal: true
21+
22+
playerpoints:
23+
Mode: playerpoints
24+
Display-Name: "点券"
25+
Decimal: false
26+
```
27+
28+
业务模块引用时,只需要写这个 key:
29+
30+
```yml
31+
Currency:
32+
Key: vault
33+
```
34+
35+
## 顶层字段
36+
37+
| 字段 | 必填 | 说明 |
38+
| --- | --- | --- |
39+
| `Mode` | 是 | 货币模式。 |
40+
| `Display-Name` | 否 | 显示名称,不写时默认使用 key。 |
41+
| `Symbol` | 否 | 显示符号。 |
42+
| `Decimal` | 否 | 是否允许小数。 |
43+
| `Actions.Take` | 自定义货币建议填写 | 扣除动作。 |
44+
| `Actions.Give` | 自定义货币建议填写 | 发放动作。 |
45+
| `Actions.Deny` | 自定义货币建议填写 | 余额不足动作。 |
46+
47+
## `Mode`
48+
49+
当前支持三类模式:
50+
51+
### 1. `vault`
52+
53+
```yml
54+
vault:
55+
Mode: vault
56+
```
57+
58+
用于调用 Vault 经济提供者。
59+
60+
### 2. `playerpoints`
61+
62+
```yml
63+
playerpoints:
64+
Mode: playerpoints
65+
Decimal: false
66+
```
67+
68+
用于调用 PlayerPoints。
69+
建议把 `Decimal` 设为 `false`。
70+
71+
### 3. PlaceholderAPI 占位符
72+
73+
```yml
74+
custom_points:
75+
Mode: "%custom_points%"
76+
```
77+
78+
这类模式通常需要同时定义 `Actions.Take / Give / Deny`,否则只能读取余额,不能完成完整结算。
79+
80+
## `Display-Name`
81+
82+
用于菜单和提示中的货币名称。
83+
84+
```yml
85+
Display-Name: "金币"
86+
```
87+
88+
建议:
89+
90+
- `vault` 写服内通用称呼,例如“金币”
91+
- `playerpoints` 写“点券”“积分”这类玩家更容易理解的名字
92+
93+
## `Symbol`
94+
95+
当前主要用于展示层,不直接参与结算。
96+
97+
```yml
98+
Symbol: "$"
99+
```
100+
101+
可写也可不写。
102+
103+
## `Decimal`
104+
105+
控制金额显示和归整方式。
106+
107+
```yml
108+
Decimal: true
109+
```
110+
111+
建议:
112+
113+
- `vault` 一般 `true`
114+
- `playerpoints` 一般 `false`
115+
- 自定义积分通常也建议 `false`
116+
117+
## `Actions.Take`
118+
119+
用于从玩家身上扣除货币。
120+
121+
```yml
122+
Actions:
123+
Take:
124+
- "console: custompoints take {player} {amount}"
125+
```
126+
127+
## `Actions.Give`
128+
129+
用于向玩家发放货币。
130+
131+
```yml
132+
Actions:
133+
Give:
134+
- "console: custompoints give {player} {amount}"
135+
```
136+
137+
## `Actions.Deny`
138+
139+
用于余额不足时的提示。
140+
141+
```yml
142+
Actions:
143+
Deny:
144+
- "tell:&c货币不足,需要 &e{need} &c,当前为 &e{balance}"
145+
```
146+
147+
## 当前支持的动作写法
148+
149+
### `console:`
150+
151+
以控制台身份执行命令:
152+
153+
```yml
154+
- "console: custompoints take {player} {amount}"
155+
```
156+
157+
### `player:`
158+
159+
以玩家身份执行命令:
160+
161+
```yml
162+
- "player: points"
163+
```
164+
165+
### `tell:`
166+
167+
直接发送提示文本:
168+
169+
```yml
170+
- "tell:&c余额不足"
171+
```
172+
173+
### 兼容旧写法
174+
175+
当前代码仍兼容一部分旧风格动作:
176+
177+
```yml
178+
- "command inline \"custompoints take {player} {amount}\" as console"
179+
- "tell color inline \"&c余额不足\""
180+
```
181+
182+
但新配置建议优先写:
183+
184+
- `console:`
185+
- `player:`
186+
- `tell:`
187+
188+
## 可用占位符
189+
190+
当前经济动作里可以稳定使用这些占位符:
191+
192+
| 占位符 | 说明 |
193+
| --- | --- |
194+
| `{player}` | 当前玩家名 |
195+
| `{sender}` | 当前玩家名 |
196+
| `{currency}` | 当前货币显示名 |
197+
| `{money}` | 当前交易金额 |
198+
| `{amount}` | 当前交易金额 |
199+
| `{need}` | 所需金额 |
200+
| `{need-money}` | 所需金额 |
201+
| `{balance}` | 当前余额 |
202+
203+
业务模块还会额外补充上下文,例如:
204+
205+
- `{buyer}`
206+
- `{seller}`
207+
- `{item}`
208+
- `{target}`
209+
210+
是否存在,取决于具体结算场景。
211+
212+
## 推荐写法
213+
214+
### 最简单的 Vault 配置
215+
216+
```yml
217+
vault:
218+
Mode: vault
219+
Display-Name: "金币"
220+
Symbol: "$"
221+
Decimal: true
222+
```
223+
224+
### PlayerPoints 配置
225+
226+
```yml
227+
playerpoints:
228+
Mode: playerpoints
229+
Display-Name: "点券"
230+
Decimal: false
231+
```
232+
233+
### 自定义积分配置
234+
235+
```yml
236+
custom_points:
237+
Mode: "%custom_points%"
238+
Display-Name: "活动积分"
239+
Decimal: false
240+
Actions:
241+
Take:
242+
- "console: custompoints take {player} {amount}"
243+
Give:
244+
- "console: custompoints give {player} {amount}"
245+
Deny:
246+
- "tell:&c活动积分不足,需要 &e{need} &c,当前为 &e{balance}"
247+
```
248+
249+
## 常见问题
250+
251+
### 自定义货币为什么能显示余额,但交易失败
252+
253+
因为你只定义了 `Mode`,没有定义:
254+
255+
- `Actions.Take`
256+
- `Actions.Give`
257+
258+
这种情况下可以读取余额,但无法真正完成扣除和发放。
259+
260+
### 为什么点券金额被取整
261+
262+
因为 `playerpoints` 或 `Decimal: false` 会把金额按整数处理。
263+
264+
### 商店没写 `Currency.Key` 会怎么样
265+
266+
会继续回退到模块级;模块级也没写时,才会回退到 `vault`。

docs/matrixshop/economy.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ MatrixShop 当前已经引入独立的经济模块,用来统一管理货币定
2323
- `PlaceholderAPI` 占位符货币
2424
- `Cart``Record` 不提供独立经济配置
2525

26+
如果你想看字段逐项说明,请继续看:
27+
28+
- [货币字段参考](./economy-reference)
29+
- [经济配置实战示例](./economy-examples)
30+
2631
## 默认文件
2732

2833
```text

sidebars.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const sidebars: SidebarsConfig = {
4747
'matrixshop/quick-start',
4848
'matrixshop/configuration-structure',
4949
'matrixshop/economy',
50+
'matrixshop/economy-reference',
5051
'matrixshop/economy-examples',
5152
'matrixshop/commands-and-permissions',
5253
'matrixshop/database-and-storage',

0 commit comments

Comments
 (0)