奖励包系统
奖励包是 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动作(本次结算数量为 total - settle),settle 更新为 total
系统 CDK 的 Owner 玩家名为 server-console-owner,使用特殊 UUID,适合发放无归属玩家的全服兑换码。
奖励包配置
奖励包配置文件为 plugins/CDKLite/reward.yml,每个顶级 key 就是一个奖励包名称。
完整默认配置
礼包1:
# 限制一个玩家领取多少次不同玩家的CDK礼包
# 支持 Kether 动态解析
limit: "if perm vip then 2 else 1"
owner: |-
tell inline "共结算 {{ &count }} 个奖励"
receive: |-
tell inline "领取了 {{ &owner }} 的CDK"
系统礼包:
# -1 或 不填写 可无限领取
limit: -1
# 填写后玩家可以在 86400 秒后再领取
period: "1d"
# 填写后需要满足 Kether 条件才能领取
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
先到先得:
# 是否限制单个 CDK 只能一个玩家领取一次
# 启用后,将无视 limit, period 设定
consume: true
# 填写后需要满足 Kether 条件才能领取
condition: 'perm newbee'
deny: |-
tell "你不满足领取该 CDK 的条件"
owner: |-
tell inline "共结算 {{ &count }} 个奖励"
receive: |-
tell inline "领取了 {{ &owner }} 的CDK"
配置项说明
| 字段 | 类型 | 说明 |
|---|---|---|
limit | String (Kether) | 领取次数限制表达式,支持 Kether 动态计算。-1 或不填写表示不限制;它不是单个 CDK 的全局可用次数控制 |
period | String | 同一玩家再次兑换同一个 CDK 的冷却时间。支持 1d(1天)、12h(12小时)、30m(30分钟)等格式 |
condition | String (Kether) | 兑换前置条件,返回布尔值的 Kether 表达式。不满足时拒绝兑换 |
consume | Boolean | 是否为一次性 CDK。设为 true 时,该 CDK 被任意玩家成功兑换后会从可领取消耗型 CDK 缓存中移除 |
deny | Kether | 当 condition 不满足时执行的动作 |
owner | Kether | Owner 结算时执行的动作。源码传入变量:&amount(本次结算数量) |
receive | Kether | Receiver 兑换时立即执行的动作。可用变量:&owner(CDK 拥有者名称) |
如果你要做「一码只能一个玩家领取」的限量码,请使用 consume: true。如果只是希望同一玩家过一段时间后可以再次领取同一个 CDK,可以使用 period。
当前默认 reward.yml 的原始模板里使用了 {{ &count }} 作为结算数量文案。源码在结算时传入的变量名是 amount,你新增或改写 owner 奖励脚本时建议使用 {{ &amount }}。
实际案例
推荐码:VIP 玩家可领 2 次,普通玩家 1 次
推荐码:
limit: "if perm vip then 2 else 1"
owner: |-
tell inline "共结算 {{ &amount }} 个奖励"
command inline "eco give {{ sender }} {{ &amount }}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 "共结算 {{ &amount }} 个奖励"
receive: |-
tell inline "领取了 {{ &owner }} 的签到码"
command inline "give {{ sender }} diamond 1" as console
period: "1d" 表示同一玩家兑换同一个 CDK 后,需要等待 24 小时才能再次兑换这个 CDK。未配置 period 时,同一玩家同一个 CDK 不能重复领取。
先到先得:一码一用
限量码:
consume: true
owner: |-
tell inline "共结算 {{ &amount }} 个奖励"
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 "共结算 {{ &amount }} 个奖励"
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 自动生成模板。