Skip to content

Examples

hp-1e edited this page Jun 7, 2026 · 2 revisions

示例 / Examples

可重复技能 / Repeatable Skill

这个示例把 rage_stack 设置为最多获得 5 次奖励的可重复技能,并在每次重复加点时提示玩家。

This example makes rage_stack repeatable for up to 5 reward grants and sends a message whenever the player repeats it.

ServerEvents.loaded(event => {
    RepeatableSkills.setRepeatable("puffish_skills:combat", "rage_stack", true, 5)
})

PufferfishSkillsEvents.skillRepeatUnlock(event => {
    if (event.getCategoryId().toString() !== "puffish_skills:combat") return
    if (event.getSkillId() !== "rage_stack") return

    const player = event.getPlayer()
    const count = event.getRepeatCount()
    const remaining = RepeatableSkills.getRemainingRepeats(player, "puffish_skills:combat", "rage_stack")

    player.tell(`怒气层数提升到了 ${count},剩余可点击次数:${remaining}`)
})

自定义解锁条件 / Custom Unlock Condition

这个示例检测玩家是否击杀过凋灵,如果满足条件就强制解锁一个技能。

This example checks whether the player has killed the Wither and force unlocks a skill when the condition is met.

ServerEvents.tick(event => {
    event.server.getPlayers().forEach(player => {
        if (player.getStats().getValue("minecraft:killed", "minecraft:wither") <= 0) return
        if (PufferfishSkills.isSkillUnlocked(player, "puffish_skills:combat", "wither_slayer")) return

        PufferfishSkills.forceUnlockSkill(player, "puffish_skills:combat", "wither_slayer")
    })
})

技能与阶段联动 / Skill Stages

这个示例在玩家解锁挖掘分类技能时添加一个游戏阶段。

This example adds a game stage when the player unlocks a skill in the mining category.

PufferfishSkillsEvents.skillUnlock(event => {
    if (event.getCategoryId().toString() !== "puffish_skills:mining") return

    event.getPlayer().stages.add("expert_miner")
})

Clone this wiki locally