Skip to content

开发者 API ​

可以将宠物作为副本通关奖励发放,也可以由任务系统给玩家当前主宠增加经验。

引入依赖 ​

使用发布包中的 FishPet JAR 作为编译依赖(provided),在你的 plugin.yml 中声明 depend: [FishPet]。通过 FishPetApiProvider.get() 获取接口;初始化尚未完成时 get() 会抛出异常,可先使用 isAvailable() 检查。下文使用简短类型名,交由 IDE 导入。

🐾 给通关玩家一只宠物 ​

java
public boolean rewardPet(Player player) {
    if (!FishPetApiProvider.isAvailable()) {
        return false;
    }
    FishPetApi api = FishPetApiProvider.get();
    Optional<PetView> pet = api.createPet(player.getUniqueId(), "chicken");
    if (!pet.isPresent()) {
        return false;
    }
    player.sendMessage("获得宠物:" + pet.get().getDisplayName());
    return true;
}

chicken 是 Pets 中的稳定种类 ID。返回 Optional 表示本次是否成功创建,并不是立即召唤到世界中的实体。调用方根据创建结果决定奖励流程是否完成。

给主宠增加经验 ​

java
public boolean rewardPetExperience(Player player, long exp) {
    FishPetApi api = FishPetApiProvider.get();
    Optional<PetView> primary = api.getPrimaryPet(player.getUniqueId());
    if (!primary.isPresent()) {
        return false;
    }
    return api.addExperience(primary.get().getPetId(), exp);
}

addExperience 的 UUID 是宠物 ID,不是玩家 ID。先找到主宠,再给这只宠物加经验。

查询与管理接口 ​

方法参数及返回值
getPet(petId)根据宠物 UUID 查询,返回 Optional。
getPets(ownerId)返回该玩家的全部宠物。
getDeployedPets(ownerId)返回当前出战宠物。
getPrimaryPet(ownerId)返回主宠 Optional。
setPrimaryPet(ownerId, petId)指定主宠,返回布尔结果。
deployPet(ownerId, petId)出战,返回是否成功。
recallPet(ownerId, petId)收回,返回是否成功。
castSkill(ownerId, petId, slot)返回 SkillCastResult,可用 isSuccess() 和 getMessage() 读取结果。
getRegisteredTraits()获取已注册特质。

PetView 提供 getPetId()、getOwnerId()、getSpeciesId()、getLevel()、getExperience()、getState()、getActiveSkills() 等读取方法。UUID 用于定位具体个体,种类 ID 用于创建同种宠物,不要混用。

插件介绍 · 命令与权限 · 功能教程