Search in sources :

Example 1 with MyPetLoadEvent

use of de.Keyle.MyPet.api.event.MyPetLoadEvent 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

MyPet (de.Keyle.MyPet.api.entity.MyPet)1 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)1 MyPetLoadEvent (de.Keyle.MyPet.api.event.MyPetLoadEvent)1 SkillInstance (de.Keyle.MyPet.api.skill.SkillInstance)1 NBTStorage (de.Keyle.MyPet.api.util.NBTStorage)1 InactiveMyPet (de.Keyle.MyPet.entity.InactiveMyPet)1 TagCompound (de.keyle.knbt.TagCompound)1