Search in sources :

Example 1 with MyPetActivatedEvent

use of de.Keyle.MyPet.api.event.MyPetActivatedEvent in project MyPet by xXKeyleXx.

the class MyPetManager method activateMyPet.

// All ----------------------------------------------------------------------
public Optional<MyPet> activateMyPet(StoredMyPet storedMyPet) {
    if (storedMyPet == null) {
        return Optional.empty();
    }
    if (!storedMyPet.getOwner().isOnline()) {
        return Optional.empty();
    }
    if (storedMyPet.getOwner().hasMyPet()) {
        if (!deactivateMyPet(storedMyPet.getOwner(), true)) {
            return Optional.empty();
        }
    }
    Event 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<Skill> skills = myPet.getSkills().all();
    if (skills.size() > 0) {
        for (Skill 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());
    event = new MyPetActivatedEvent(myPet);
    Bukkit.getServer().getPluginManager().callEvent(event);
    return Optional.of(myPet);
}
Also used : MyPetLoadEvent(de.Keyle.MyPet.api.event.MyPetLoadEvent) Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) MyPet(de.Keyle.MyPet.api.entity.MyPet) InactiveMyPet(de.Keyle.MyPet.entity.InactiveMyPet) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet) MyPetActivatedEvent(de.Keyle.MyPet.api.event.MyPetActivatedEvent) Event(org.bukkit.event.Event) MyPetLoadEvent(de.Keyle.MyPet.api.event.MyPetLoadEvent) NBTStorage(de.Keyle.MyPet.api.util.NBTStorage) MyPetActivatedEvent(de.Keyle.MyPet.api.event.MyPetActivatedEvent) TagCompound(de.keyle.knbt.TagCompound)

Aggregations

MyPet (de.Keyle.MyPet.api.entity.MyPet)1 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)1 MyPetActivatedEvent (de.Keyle.MyPet.api.event.MyPetActivatedEvent)1 MyPetLoadEvent (de.Keyle.MyPet.api.event.MyPetLoadEvent)1 Skill (de.Keyle.MyPet.api.skill.skilltree.Skill)1 NBTStorage (de.Keyle.MyPet.api.util.NBTStorage)1 InactiveMyPet (de.Keyle.MyPet.entity.InactiveMyPet)1 TagCompound (de.keyle.knbt.TagCompound)1 Event (org.bukkit.event.Event)1