Exemplo n.º 1
0
 public LivingPet createPet(
     Player owner, PetType petType, PetType mountType, boolean sendFailMessage) {
   removePets(owner);
   if (!WorldUtil.allowPets(owner.getLocation())) {
     if (sendFailMessage) {
       Lang.sendTo(
           owner,
           Lang.PETS_DISABLED_HERE
               .toString()
               .replace("%world%", StringUtil.capitalise(owner.getWorld().getName())));
     }
     return null;
   }
   if (!ec.options.allowPetType(petType)) {
     if (sendFailMessage) {
       Lang.sendTo(
           owner,
           Lang.PET_TYPE_DISABLED
               .toString()
               .replace("%type%", StringUtil.capitalise(petType.toString())));
     }
     return null;
   }
   LivingPet pi = petType.getNewPetInstance(owner, petType);
   // Pet pi = new Pet(owner, petType);
   pi.createMount(mountType, true);
   forceAllValidData(pi);
   pets.add(pi);
   // saveFileData("autosave", pi);
   // ec.SPH.saveToDatabase(pi, false);
   return pi;
 }
Exemplo n.º 2
0
  // Force all data specified in config file and notify player.
  public void forceAllValidData(LivingPet pi) {
    ArrayList<PetData> tempData = new ArrayList<PetData>();
    for (PetData data : PetData.values()) {
      if (ec.options.forceData(pi.getPetType(), data)) {
        tempData.add(data);
      }
    }
    setData(pi, tempData.toArray(new PetData[tempData.size()]), true);

    ArrayList<PetData> tempMountData = new ArrayList<PetData>();
    if (pi.getMount() != null) {
      for (PetData data : PetData.values()) {
        if (ec.options.forceData(pi.getPetType(), data)) {
          tempMountData.add(data);
        }
      }
      setData(pi.getMount(), tempMountData.toArray(new PetData[tempData.size()]), true);
    }

    if ((Boolean) ec.options.getConfigOption("sendForceMessage", true)) {
      String dataToString = " ";
      if (!tempMountData.isEmpty()) {
        dataToString = StringUtil.dataToString(tempData);
      } else {
        dataToString = StringUtil.dataToString(tempData, tempMountData);
      }
      if (dataToString != " ") {
        Lang.sendTo(
            pi.getOwner(), Lang.DATA_FORCE_MESSAGE.toString().replace("%data%", dataToString));
      }
    }
  }
Exemplo n.º 3
0
 public LivingPet loadPets(
     Player p, boolean findDefault, boolean sendMessage, boolean checkWorldOverride) {
   EchoPet ec = EchoPet.getPluginInstance();
   if (ec.options.sqlOverride()) {
     LivingPet pet = ec.SPH.createPetFromDatabase(p);
     if (pet == null) {
       return null;
     } else {
       if (sendMessage) {
         Lang.sendTo(
             p,
             Lang.DATABASE_PET_LOAD.toString().replace("%petname%", pet.getPetName().toString()));
       }
     }
     return pet;
   } else if (ec.getPetConfig().get("default." + p.getName() + ".pet.type") != null
       && findDefault) {
     LivingPet pi = ec.PH.createPetFromFile("default", p);
     if (pi == null) {
       return null;
     } else {
       if (sendMessage) {
         Lang.sendTo(
             p, Lang.DEFAULT_PET_LOAD.toString().replace("%petname%", pi.getPetName().toString()));
       }
     }
     return pi;
   } else if ((checkWorldOverride
           && (Boolean) ec.options.getConfigOption("multiworldLoadOverride", true))
       || (Boolean) ec.options.getConfigOption("loadSavedPets", true)) {
     if (ec.getPetConfig().get("autosave." + p.getName() + ".pet.type") != null) {
       LivingPet pi = ec.PH.createPetFromFile("autosave", p);
       if (pi == null) {
         return null;
       } else {
         if (sendMessage) {
           Lang.sendTo(
               p,
               Lang.AUTOSAVE_PET_LOAD.toString().replace("%petname%", pi.getPetName().toString()));
         }
       }
       return pi;
     }
   }
   return null;
 }