Search in sources :

Example 1 with NBTStorage

use of de.Keyle.MyPet.api.util.NBTStorage 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.getHealth()));
    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<Skill> skillList = this.getSkills().all();
    if (skillList.size() > 0) {
        for (Skill 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 : Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) NBTStorage(de.Keyle.MyPet.api.util.NBTStorage)

Example 2 with NBTStorage

use of de.Keyle.MyPet.api.util.NBTStorage 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)

Example 3 with NBTStorage

use of de.Keyle.MyPet.api.util.NBTStorage 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)

Example 4 with NBTStorage

use of de.Keyle.MyPet.api.util.NBTStorage in project MyPet by xXKeyleXx.

the class MyPet method getSkillInfo.

public TagCompound getSkillInfo() {
    TagCompound skillsNBT = new TagCompound();
    Collection<Skill> skillList = this.getSkills().all();
    if (skillList.size() > 0) {
        for (Skill 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 : Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) NBTStorage(de.Keyle.MyPet.api.util.NBTStorage)

Example 5 with NBTStorage

use of de.Keyle.MyPet.api.util.NBTStorage in project MyPet by xXKeyleXx.

the class InactiveMyPet method setSkills.

public void setSkills(Collection<Skill> skills) {
    if (NBTSkills == null) {
        NBTSkills = new TagCompound();
    }
    for (Skill 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 : Skill(de.Keyle.MyPet.api.skill.skilltree.Skill) NBTStorage(de.Keyle.MyPet.api.util.NBTStorage)

Aggregations

NBTStorage (de.Keyle.MyPet.api.util.NBTStorage)5 Skill (de.Keyle.MyPet.api.skill.skilltree.Skill)4 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 SkillInstance (de.Keyle.MyPet.api.skill.SkillInstance)1 InactiveMyPet (de.Keyle.MyPet.entity.InactiveMyPet)1 TagCompound (de.keyle.knbt.TagCompound)1 Event (org.bukkit.event.Event)1