奖励包系统
奖励包是 CDKLite 的核心功能。每个 CDK 绑定一个奖励包,当玩家兑换时,系统会根据配置分别向 Owner(拥有者)和 Receiver(使用者)执行对应的 Kether 动作。
Owner / Receiver 双角色模型
CDKLite 采用双角色模型,这是它区别于普通兑换码插件的关键设计:
- Owner(拥有者):CDK 的归属者。当有人使用该 CDK 时,Owner 的
total计数 +1。Owner 通过/cdklite reward结算累积的奖励 - Receiver(使用者):实际输入兑换码的玩家,兑换后立即执行
receive动作
完整流程
- 管理员执行
/cdklite create Steve 礼包1→ 创建 OwnerEntity(settle=0, total=0) - 玩家 Alex 执行
/cdk <兑换码>→ 验证通过 → 创建 ReceiveEntity,Owner 的 total +1,执行receive动作 - Steve 执行
/cdklite reward→ 执行owner动作(&count= total - settle),settle 更新为 total
信息
系统 CDK 的 Owner 玩家名为 server-console-owner,使用特殊 UUID,适合发放无归属的全服兑换码。
奖励包配置
奖励包配置文件为 plugins/CDKLite/reward.yml,每个顶级 key 就是一个奖励包名称。
完整默认配置
礼包1:
limit: "if perm vip then 2 else 1"
owner: |-
tell inline "共结算 {{ &count }} 个奖励"
receive: |-
tell inline "领取了 {{ &owner }} 的CDK"
系统礼包:
limit: -1
period: "1d"
condition: 'not perm newbee'
deny: |-
tell "你不满足领取该 CDK 的条件"
owner: |-
tell inline "共结算 {{ &count }} 个奖励"
receive: |-
tell inline "领取了 {{ &owner }} 的CDK"
command inline "lp u {{ sender }} perm set newbee true" as console
先到先得:
consume: true
condition: 'perm newbee'
deny: |-
tell "你不满足领取该 CDK 的条件"
owner: |-
tell inline "共结算 {{ &count }} 个奖励"
receive: |-
tell inline "领取了 {{ &owner }} 的CDK"
配置项说明
| 字段 | 类型 | 说明 |
|---|---|---|
limit | String (Kether) | 每个玩家最多可兑换该 CDK 的次数。支持 Kether 表达式动态计算。-1 表示不限次数 |
period | String | 兑换冷却时间。支持 1d(1天)、12h(12小时)、30m(30分钟)等格式 |
condition | String (Kether) | 兑换前置条件,返回布尔值的 Kether 表达式。不满足时拒绝兑换 |
consume | Boolean | 是否为一次性 CDK。设为 true 时,该 CDK 只能被一个玩家兑换 |
deny | Kether | 当 condition 不满足时执行的动作 |
owner | Kether | Owner 结算时执行的动作。可用变量:&count(本次结算数量) |
receive | Kether | Receiver 兑换时立即执行的动作。可用变量:&owner(CDK 拥有者名称) |
实际案例
推荐码:VIP 玩家可领 2 次,普通玩家 1 次
推荐码:
limit: "if perm vip then 2 else 1"
owner: |-
tell inline "共结算 {{ &count }} 个奖励"
command inline "eco give {{ sender }} {{ &count }}00" as console
receive: |-
tell inline "领取了 {{ &owner }} 的推荐码"
command inline "eco give {{ sender }} 50" as console
limit 使用 Kether 表达式,根据玩家是否有 vip 权限动态返回不同的次数上限。
每日签到码:每天限领一次
签到码:
limit: -1
period: "1d"
owner: |-
tell inline "共结算 {{ &count }} 个奖励"
receive: |-
tell inline "领取了 {{ &owner }} 的签到码"
command inline "give {{ sender }} diamond 1" as console
period: "1d" 表示同一玩家每 24 小时只能兑换一次。
先到先得:一码一用
限量码:
consume: true
owner: |-
tell inline "共结算 {{ &count }} 个奖励"
receive: |-
tell inline "领取了 {{ &owner }} 的限量码"
command inline "give {{ sender }} diamond_block 64" as console
consume: true 表示这个 CDK 只能被一个玩家兑换,兑换后即失效。
带条件的礼包:需要特定权限
新手礼包:
condition: 'not perm newbee'
deny: |-
tell "你已经领取过新手礼包了"
owner: |-
tell inline "共结算 {{ &count }} 个奖励"
receive: |-
tell inline "领取了 {{ &owner }} 的CDK"
command inline "lp u {{ sender }} perm set newbee true" as console
condition 检查玩家是否没有 newbee 权限(即未领取过),领取后通过 receive 动作给玩家加上 newbee 权限,防止重复领取。
Kether 动作参考
奖励包中的 owner、receive、deny 字段都使用 TabooLib Kether 脚本语法。常用动作:
| 动作 | 示例 | 说明 |
|---|---|---|
tell | tell "消息内容" | 向玩家发送消息 |
tell inline | tell inline "包含 {{ 变量 }} 的消息" | 发送包含内联变量的消息 |
command ... as console | command inline "give {{ sender }} diamond 1" as console | 以控制台身份执行命令 |
自定义 Kether 动作
CDKLite 注册了一个自定义 Kether 动作:
cdklite rand <N>
生成 N 个随机字符,字符集由 config.yml 中的 random_cdk_chars 决定。主要用于 CDK 自动生成模板。