外观
开发者 API
域之天赋树提供点数、节点等级、升级与退点接口。可用于任务奖励、职业插件和自定义菜单。
接入
将 YuTalentTree JAR 加入项目编译依赖(provided),在插件描述中声明 depend: [YuTalentTree]。代码使用简短类名,由 IDE 自动导入。
🎁 任务完成时赠送 3 个天赋点
java
public void grantPoints(Player player) {
YuTalentAPI api = YuTalentAPI.get();
UUID playerId = player.getUniqueId();
api.addPoints(playerId, "default", 3);
player.sendMessage("当前天赋点:" + api.getPoints(playerId, "default"));
}default 是默认点数池 ID。想发放退点券就使用配置中的退点池 ID(默认 respec)。
学习天赋
java
public void learnTalent(Player player) {
YuTalentAPI api = YuTalentAPI.get();
YuTalentAPI.LearnResult result = api.learn(player, "基础分支", "基础训练");
switch (result) {
case SUCCESS:
player.sendMessage("学习成功");
break;
case NOT_ENOUGH_POINTS:
player.sendMessage("天赋点不足");
break;
case REQUIREMENTS:
player.sendMessage("尚未满足前置条件");
break;
default:
player.sendMessage("学习失败:" + result.name());
}
}树 ID 和节点 ID 使用 YAML 中的真实键,而不是带颜色的 display。learn 会执行插件自己的条件及点数检查;setNodeLevel 属于直接设置等级的管理接口,不适合作为普通升级按钮。
退点与查询
java
YuTalentAPI api = YuTalentAPI.get();
int level = api.getNodeLevel(player.getUniqueId(), "基础分支", "基础训练");
YuTalentAPI.RefundResult result = api.refund(player, "基础分支", "基础训练");
if (result == YuTalentAPI.RefundResult.BLOCKED_BY_DEPENDENCY) {
player.sendMessage("请先退掉依赖此节点的其他天赋");
}退点结果还包括 SUCCESS、TREE_NOT_FOUND、NODE_NOT_FOUND、NOT_LEARNED、NOT_ENOUGH_REFUND_POINTS。
| 方法 | 用途 |
|---|---|
getTree(treeId) / getTrees() | 查询树配置对象或所有树。 |
getNodeLevel(uuid, treeId, nodeId) | 当前节点等级。 |
getPoints(uuid, poolId) | 查询对应点数池余额。 |
addPoints(uuid, poolId, amount) | 增加点数。 |
setPoints(uuid, poolId, amount) | 直接设置点数。 |
setNodeLevel(uuid, treeId, nodeId, level) | 管理用途:直接设置节点等级。 |
canAccess(player, tree) | 判断能否访问指定树。 |
getTreeSpent(uuid, treeId) | 查询该树累计消耗点数。 |
