Search in sources :

Example 1 with SkillInstance

use of de.Keyle.MyPet.api.skill.SkillInstance in project MyPet by xXKeyleXx.

the class MyPet method save.

@Override
public TagCompound save() {
    TagCompound petNBT = new TagCompound();
    petNBT.getCompoundData().put("UUID", new TagString(getUUID().toString()));
    petNBT.getCompoundData().put("Type", new TagString(this.getPetType().name()));
    petNBT.getCompoundData().put("Health", new TagDouble(this.health));
    petNBT.getCompoundData().put("Respawntime", new TagInt(this.respawnTime));
    petNBT.getCompoundData().put("Hunger", new TagDouble(this.saturation));
    petNBT.getCompoundData().put("Name", new TagString(this.petName));
    petNBT.getCompoundData().put("WorldGroup", new TagString(this.worldGroup));
    petNBT.getCompoundData().put("Exp", new TagDouble(this.getExp()));
    petNBT.getCompoundData().put("LastUsed", new TagLong(this.lastUsed));
    petNBT.getCompoundData().put("Info", writeExtendedInfo());
    petNBT.getCompoundData().put("Internal-Owner-UUID", new TagString(this.petOwner.getInternalUUID().toString()));
    petNBT.getCompoundData().put("Wants-To-Respawn", new TagByte(wantsToRespawn));
    if (this.skillTree != null) {
        petNBT.getCompoundData().put("Skilltree", new TagString(skillTree.getName()));
    }
    TagCompound skillsNBT = new TagCompound();
    Collection<SkillInstance> skillList = this.getSkills().getSkills();
    if (skillList.size() > 0) {
        for (SkillInstance skill : skillList) {
            if (skill instanceof NBTStorage) {
                NBTStorage storageSkill = (NBTStorage) skill;
                TagCompound s = storageSkill.save();
                if (s != null) {
                    skillsNBT.getCompoundData().put(skill.getName(), s);
                }
            }
        }
    }
    petNBT.getCompoundData().put("Skills", skillsNBT);
    return petNBT;
}
Also used : SkillInstance(de.Keyle.MyPet.api.skill.SkillInstance) NBTStorage(de.Keyle.MyPet.api.util.NBTStorage)

Example 2 with SkillInstance

use of de.Keyle.MyPet.api.skill.SkillInstance in project MyPet by xXKeyleXx.

the class MyPet method schedule.

public void schedule() {
    if (status != PetState.Despawned && getOwner().isOnline()) {
        for (SkillInstance skill : skills.getSkills()) {
            if (skill instanceof Scheduler) {
                ((Scheduler) skill).schedule();
            }
        }
        if (status == PetState.Dead) {
            respawnTime--;
            if (respawnTime <= 0) {
                respawnPet();
            } else if (MyPetApi.getPluginHookManager().isHookActive(VaultHook.class) && getOwner().hasAutoRespawnEnabled() && respawnTime >= getOwner().getAutoRespawnMin() && Permissions.has(getOwner().getPlayer(), "MyPet.user.respawn")) {
                double cost = respawnTime * Configuration.Respawn.COSTS_FACTOR + Configuration.Respawn.COSTS_FIXED;
                VaultHook vaultHook = MyPetApi.getPluginHookManager().getHook(VaultHook.class);
                if (vaultHook.canPay(getOwner().getPlayer(), cost)) {
                    vaultHook.pay(getOwner().getPlayer(), cost);
                    getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Respawn.Paid", petOwner.getLanguage()), petName, cost + " " + vaultHook.currencyNameSingular()));
                    respawnTime = 1;
                }
            }
        }
        if (status == PetState.Here) {
            if (Configuration.HungerSystem.USE_HUNGER_SYSTEM) {
                if (saturation > 1 && --hungerTime <= 0) {
                    saturation--;
                    hungerTime = Configuration.HungerSystem.HUNGER_SYSTEM_TIME;
                    if (saturation == 66) {
                        getOwner().sendMessage(Util.formatText(Translation.getString("Message.Hunger.Rumbling", getOwner()), getPetName()));
                    } else if (saturation == 33) {
                        getOwner().sendMessage(Util.formatText(Translation.getString("Message.Hunger.Hungry", getOwner()), getPetName()));
                    } else if (saturation == 1) {
                        getOwner().sendMessage(Util.formatText(Translation.getString("Message.Hunger.Starving", getOwner()), getPetName()));
                    }
                }
                if (saturation == 1 && getHealth() >= 2) {
                    getEntity().get().damage(1.);
                }
            }
        }
    }
}
Also used : SkillInstance(de.Keyle.MyPet.api.skill.SkillInstance) Scheduler(de.Keyle.MyPet.api.util.Scheduler) VaultHook(de.Keyle.MyPet.util.hooks.VaultHook)

Example 3 with SkillInstance

use of de.Keyle.MyPet.api.skill.SkillInstance in project MyPet by xXKeyleXx.

the class CommandSkill method onCommand.

public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player) {
        Player petOwner = (Player) sender;
        if (args.length > 0 && Permissions.has(petOwner, "MyPet.admin", false)) {
            petOwner = Bukkit.getServer().getPlayer(args[0]);
            if (petOwner == null || !petOwner.isOnline()) {
                sender.sendMessage(Translation.getString("Message.No.PlayerOnline", petOwner));
                return true;
            } else if (!MyPetApi.getMyPetManager().hasActiveMyPet(petOwner)) {
                sender.sendMessage(Util.formatText(Translation.getString("Message.No.UserHavePet", petOwner), petOwner.getName()));
                return true;
            }
        }
        if (MyPetApi.getMyPetManager().hasActiveMyPet(petOwner)) {
            MyPet myPet = MyPetApi.getMyPetManager().getMyPet(petOwner);
            myPet.autoAssignSkilltree();
            sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Skills.Show", petOwner), myPet.getPetName(), (myPet.getSkilltree() == null ? "-" : myPet.getSkilltree().getDisplayName())));
            for (SkillInstance skill : myPet.getSkills().getSkills()) {
                if (skill.isActive()) {
                    sender.sendMessage("  " + ChatColor.GREEN + skill.getName(MyPetApi.getPlatformHelper().getPlayerLanguage(petOwner)) + ChatColor.RESET + " " + skill.getFormattedValue());
                }
            }
            return true;
        } else {
            sender.sendMessage(Translation.getString("Message.No.HasPet", petOwner));
        }
        return true;
    }
    sender.sendMessage("You can't use this command from server console!");
    return true;
}
Also used : Player(org.bukkit.entity.Player) SkillInstance(de.Keyle.MyPet.api.skill.SkillInstance) MyPet(de.Keyle.MyPet.api.entity.MyPet)

Example 4 with SkillInstance

use of de.Keyle.MyPet.api.skill.SkillInstance in project MyPet by xXKeyleXx.

the class CommandOptionReloadSkilltrees method onCommandOption.

@Override
public boolean onCommandOption(CommandSender sender, String[] args) {
    SkillTreeMobType.clearMobTypes();
    String[] petTypes = new String[MyPetType.values().length + 1];
    petTypes[0] = "default";
    for (int i = 1; i <= MyPetType.values().length; i++) {
        petTypes[i] = MyPetType.values()[i - 1].name();
    }
    for (MyPet myPet : MyPetApi.getMyPetManager().getAllActiveMyPets()) {
        myPet.getSkills().reset();
    }
    SkillTreeMobType.clearMobTypes();
    SkillTreeLoaderNBT.getSkilltreeLoader().loadSkillTrees(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "skilltrees", petTypes);
    Set<String> skilltreeNames = new LinkedHashSet<>();
    for (MyPetType mobType : MyPetType.values()) {
        SkillTreeMobType skillTreeMobType = SkillTreeMobType.byPetType(mobType);
        SkillTreeLoader.addDefault(skillTreeMobType);
        SkillTreeLoader.manageInheritance(skillTreeMobType);
        skilltreeNames.addAll(skillTreeMobType.getSkillTreeNames());
    }
    // register skilltree permissions
    for (String skilltreeName : skilltreeNames) {
        try {
            Bukkit.getPluginManager().addPermission(new Permission("MyPet.custom.skilltree." + skilltreeName));
        } catch (Exception ignored) {
        }
    }
    for (MyPet myPet : MyPetApi.getMyPetManager().getAllActiveMyPets()) {
        myPet.getSkills().reset();
        SkillTree skillTree = myPet.getSkilltree();
        if (skillTree != null) {
            String skilltreeName = skillTree.getName();
            if (SkillTreeMobType.hasMobType(myPet.getPetType())) {
                SkillTreeMobType mobType = SkillTreeMobType.byPetType(myPet.getPetType());
                if (mobType.hasSkillTree(skilltreeName)) {
                    skillTree = mobType.getSkillTree(skilltreeName);
                } else {
                    skillTree = null;
                }
            } else {
                skillTree = null;
            }
        }
        myPet.setSkilltree(skillTree);
        if (skillTree != null) {
            sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Skills.Show", myPet.getOwner()), myPet.getPetName(), (myPet.getSkilltree() == null ? "-" : myPet.getSkilltree().getDisplayName())));
            for (SkillInstance skill : myPet.getSkills().getSkills()) {
                if (skill.isActive()) {
                    myPet.getOwner().sendMessage("  " + ChatColor.GREEN + skill.getName(myPet.getOwner().getLanguage()) + ChatColor.RESET + " " + skill.getFormattedValue());
                }
            }
        }
    }
    sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] skilltrees loaded!");
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SkillInstance(de.Keyle.MyPet.api.skill.SkillInstance) MyPet(de.Keyle.MyPet.api.entity.MyPet) MyPetType(de.Keyle.MyPet.api.entity.MyPetType) SkillTreeMobType(de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType) Permission(org.bukkit.permissions.Permission) SkillTree(de.Keyle.MyPet.api.skill.skilltree.SkillTree)

Example 5 with SkillInstance

use of de.Keyle.MyPet.api.skill.SkillInstance in project MyPet by xXKeyleXx.

the class InactiveMyPet method setSkills.

public void setSkills(Collection<SkillInstance> skills) {
    if (NBTSkills == null) {
        NBTSkills = new TagCompound();
    }
    for (SkillInstance skill : skills) {
        if (skill instanceof NBTStorage) {
            NBTStorage storageSkill = (NBTStorage) skill;
            TagCompound s = storageSkill.save();
            if (s != null) {
                this.NBTSkills.getCompoundData().put(skill.getName(), s);
            }
        }
    }
}
Also used : SkillInstance(de.Keyle.MyPet.api.skill.SkillInstance) NBTStorage(de.Keyle.MyPet.api.util.NBTStorage)

Aggregations

SkillInstance (de.Keyle.MyPet.api.skill.SkillInstance)7 NBTStorage (de.Keyle.MyPet.api.util.NBTStorage)4 MyPet (de.Keyle.MyPet.api.entity.MyPet)3 MyPetType (de.Keyle.MyPet.api.entity.MyPetType)1 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)1 MyPetLoadEvent (de.Keyle.MyPet.api.event.MyPetLoadEvent)1 SkillTree (de.Keyle.MyPet.api.skill.skilltree.SkillTree)1 SkillTreeMobType (de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType)1 Scheduler (de.Keyle.MyPet.api.util.Scheduler)1 InactiveMyPet (de.Keyle.MyPet.entity.InactiveMyPet)1 VaultHook (de.Keyle.MyPet.util.hooks.VaultHook)1 TagCompound (de.keyle.knbt.TagCompound)1 LinkedHashSet (java.util.LinkedHashSet)1 Player (org.bukkit.entity.Player)1 Permission (org.bukkit.permissions.Permission)1