Example #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;
  }
Example #2
0
 public static void addInactiveMyPet(InactiveMyPet inactiveMyPet) {
   lInactivePets.add(inactiveMyPet);
   if (mInctivePets.containsKey(inactiveMyPet.getPetOwner())) {
     List<InactiveMyPet> inactiveMyPetList = mInctivePets.get(inactiveMyPet.getPetOwner());
     if (!inactiveMyPetList.contains(inactiveMyPet)) {
       inactiveMyPetList.add(inactiveMyPet);
     }
   } else {
     List<InactiveMyPet> inactiveMyPetList = new ArrayList<InactiveMyPet>();
     inactiveMyPetList.add(inactiveMyPet);
     mInctivePets.put(inactiveMyPet.getPetOwner(), inactiveMyPetList);
   }
 }
Example #3
0
 public static void removeInactiveMyPet(InactiveMyPet inactiveMyPet) {
   if (inactiveMyPet == null) {
     return;
   }
   lInactivePets.remove(inactiveMyPet);
   if (mInctivePets.containsKey(inactiveMyPet.getPetOwner())) {
     List<InactiveMyPet> myPetList = mInctivePets.get(inactiveMyPet.getPetOwner());
     if (myPetList.contains(inactiveMyPet)) {
       myPetList.remove(inactiveMyPet);
     }
     if (myPetList.size() == 0) {
       mInctivePets.remove(inactiveMyPet.getPetOwner());
     }
   }
 }
Example #4
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;
 }