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;
}
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);
}
}
}
}
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);
}
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;
}
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);
}
}
}
}
Aggregations