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