示例#1
0
  private static MyPet getMyPet(InactiveMyPet inactiveMyPet) {
    if (inactiveMyPet.getPetOwner().isOnline()) {
      MyPet activeMyPet =
          inactiveMyPet.getPetType().getNewMyPetInstance(inactiveMyPet.getPetOwner());
      activeMyPet.setLocation(
          inactiveMyPet.getLocation() == null
              ? inactiveMyPet.getPetOwner().getPlayer().getLocation()
              : inactiveMyPet.getLocation());
      activeMyPet.petName = inactiveMyPet.getPetName();
      activeMyPet.respawnTime = inactiveMyPet.getRespawnTime();
      activeMyPet.setSkilltree(inactiveMyPet.getSkillTree());
      activeMyPet.setExtendedInfo(inactiveMyPet.getInfo());

      if (activeMyPet.respawnTime > 0) {
        activeMyPet.status = PetState.Dead;
      } else {
        activeMyPet.status = PetState.Despawned;
      }

      activeMyPet.getExperience().setExp(inactiveMyPet.getExp());
      Collection<MyPetGenericSkill> skills = activeMyPet.getSkills().getSkills();
      if (skills.size() > 0) {
        for (MyPetGenericSkill skill : skills) {
          if (inactiveMyPet.getSkills().hasKey(skill.getName())) {
            skill.load(inactiveMyPet.getSkills().getCompound(skill.getName()));
          }
        }
      }
      activeMyPet.setHealth(inactiveMyPet.getHealth());
      activeMyPet.setHungerValue(inactiveMyPet.getHungerValue());
      return activeMyPet;
    }
    return null;
  }
示例#2
0
 public static MyPet setMyPetActive(InactiveMyPet inactiveMyPet) {
   if (hasMyPet(inactiveMyPet.getPetName())) {
     MyPet activeMyPet = getMyPet(inactiveMyPet.getPetOwner().getPlayer());
     MyPetSelectSetInactiveEvent event = new MyPetSelectSetInactiveEvent(activeMyPet);
     getServer().getPluginManager().callEvent(event);
     if (event.isCancelled()) {
       return null;
     }
     setMyPetInactive(inactiveMyPet.getPetOwner().getPlayer());
   }
   MyPetSelectSetActiveEvent event = new MyPetSelectSetActiveEvent(inactiveMyPet);
   getServer().getPluginManager().callEvent(event);
   if (event.isCancelled()) {
     return null;
   }
   MyPet activeMyPet = getMyPet(inactiveMyPet);
   addMyPet(activeMyPet);
   removeInactiveMyPet(inactiveMyPet);
   MyPetUtil.getDebugLogger().info("   A: " + activeMyPet);
   MyPetUtil.getDebugLogger().info("   I: " + inactiveMyPet);
   return activeMyPet;
 }