Search in sources :

Example 6 with SkillInstance

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

the class MyPet method getSkillInfo.

public TagCompound getSkillInfo() {
    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);
                }
            }
        }
    }
    return skillsNBT;
}
Also used : SkillInstance(de.Keyle.MyPet.api.skill.SkillInstance) NBTStorage(de.Keyle.MyPet.api.util.NBTStorage)

Example 7 with SkillInstance

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

the class MyPetManager method activateMyPet.

// All ----------------------------------------------------------------------
public Optional<MyPet> activateMyPet(StoredMyPet storedMyPet) {
    if (!storedMyPet.getOwner().isOnline()) {
        return Optional.absent();
    }
    if (storedMyPet.getOwner().hasMyPet()) {
        if (!deactivateMyPet(storedMyPet.getOwner(), true)) {
            return Optional.absent();
        }
    }
    MyPetLoadEvent event = new MyPetLoadEvent(storedMyPet);
    Bukkit.getServer().getPluginManager().callEvent(event);
    MyPet myPet = MyPetClass.getByMyPetType(storedMyPet.getPetType()).getNewMyPetInstance(storedMyPet.getOwner());
    myPet.setUUID(storedMyPet.getUUID());
    myPet.setPetName(storedMyPet.getPetName());
    myPet.setRespawnTime(storedMyPet.getRespawnTime());
    myPet.setWorldGroup(storedMyPet.getWorldGroup());
    myPet.setInfo(storedMyPet.getInfo());
    myPet.setLastUsed(storedMyPet.getLastUsed());
    myPet.setWantsToRespawn(storedMyPet.wantsToRespawn());
    myPet.getExperience().setExp(storedMyPet.getExp());
    myPet.setSkilltree(storedMyPet.getSkilltree());
    Collection<SkillInstance> skills = myPet.getSkills().getSkills();
    if (skills.size() > 0) {
        for (SkillInstance skill : skills) {
            if (skill instanceof NBTStorage) {
                NBTStorage storageSkill = (NBTStorage) skill;
                if (storedMyPet.getSkillInfo().getCompoundData().containsKey(skill.getName())) {
                    storageSkill.load(storedMyPet.getSkillInfo().getAs(skill.getName(), TagCompound.class));
                }
            }
        }
    }
    myPet.setHealth(storedMyPet.getHealth());
    myPet.setSaturation(storedMyPet.getSaturation());
    mActivePetsPlayer.put(myPet, myPet.getOwner());
    return Optional.of(myPet);
}
Also used : MyPetLoadEvent(de.Keyle.MyPet.api.event.MyPetLoadEvent) SkillInstance(de.Keyle.MyPet.api.skill.SkillInstance) MyPet(de.Keyle.MyPet.api.entity.MyPet) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet) NBTStorage(de.Keyle.MyPet.api.util.NBTStorage) TagCompound(de.keyle.knbt.TagCompound)

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