Exemplo n.º 1
0
  public void saveFileData(String type, LivingPet pi) {
    clearFileData(type, pi);
    try {
      String oName = pi.getOwner().getName();
      String path = type + "." + oName;
      PetType petType = pi.getPetType();

      ec.getPetConfig().set(path + ".pet.type", petType.toString());
      ec.getPetConfig().set(path + ".pet.name", pi.getNameToString());

      for (PetData pd : pi.getActiveData()) {
        ec.getPetConfig().set(path + ".pet.data." + pd.toString().toLowerCase(), true);
      }

      if (pi.getMount() != null) {
        PetType mountType = pi.getMount().getPetType();

        ec.getPetConfig().set(path + ".mount.type", mountType.toString());
        ec.getPetConfig().set(path + ".mount.name", pi.getMount().getNameToString());
        for (PetData pd : pi.getMount().getActiveData()) {
          ec.getPetConfig().set(path + ".mount.data." + pd.toString().toLowerCase(), true);
        }
      }
    } catch (Exception e) {
    }
    ec.getPetConfig().saveConfig();
  }
Exemplo n.º 2
0
 public void clearAllFileData() {
   for (String key : ec.getPetConfig().getKeys(true)) {
     if (ec.getPetConfig().get(key) != null) {
       ec.getPetConfig().set(key, null);
     }
   }
   ec.getPetConfig().saveConfig();
 }
Exemplo n.º 3
0
 public void updateFileData(String type, LivingPet pet, ArrayList<PetData> list, boolean b) {
   ec.SPH.updateDatabase(pet.getOwner(), list, b, pet.isMount());
   String w = pet.getOwner().getWorld().getName();
   String path = type + "." + w + "." + pet.getOwner().getName();
   for (PetData pd : list) {
     ec.getPetConfig().set(path + ".pet.data." + pd.toString().toLowerCase(), b);
   }
   ec.getPetConfig().saveConfig();
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 public void clearFileData(String type, String pName) {
   String path = type + "." + pName;
   ec.getPetConfig().set(path, null);
   /*if (ec.getPetConfig().get(path + ".pet.type") != null) {
   	for (String key : ec.getPetConfig().getConfigurationSection(path).getKeys(false)) {
   		for (String key1 : ec.getPetConfig().getConfigurationSection(path + "." + key).getKeys(false)) {
   			if (ec.getPetConfig().get(path + "." + key + "." + key1) != null) {
   				ec.getPetConfig().set(path + "." + key + "." + key1, null);
   			}
   		}
   		if (ec.getPetConfig().get(path + "." + key) != null) {
   			ec.getPetConfig().set(path + "." + key, null);
   		}
   	}
   }*/
   ec.getPetConfig().saveConfig();
 }
Exemplo n.º 6
0
  public void saveFileData(String type, String name, UnorganisedPetData UPD) {
    clearFileData(type, name);
    PetType pt = UPD.petType;
    PetData[] data = UPD.petDataList.toArray(new PetData[UPD.petDataList.size()]);
    String petName = UPD.petName;

    String path = type + "." + name;
    try {
      ec.getPetConfig().set(path + ".pet.type", pt.toString());
      ec.getPetConfig().set(path + ".pet.name", petName);

      for (PetData pd : data) {
        ec.getPetConfig().set(path + ".pet.data." + pd.toString().toLowerCase(), true);
      }

    } catch (Exception e) {
    }
    ec.getPetConfig().saveConfig();
  }
Exemplo n.º 7
0
  public void saveFileData(
      String type, String name, UnorganisedPetData UPD, UnorganisedPetData UMD) {
    clearFileData(type, name);
    PetType pt = UPD.petType;
    PetData[] data = UPD.petDataList.toArray(new PetData[UPD.petDataList.size()]);
    String petName = UPD.petName;
    if (UPD.petName == null || UPD.petName.equalsIgnoreCase("")) {
      petName = pt.getDefaultName(name);
    }
    PetType mountType = UMD.petType;
    PetData[] mountData = UMD.petDataList.toArray(new PetData[UMD.petDataList.size()]);
    String mountName = UMD.petName;
    if (UMD.petName == null || UMD.petName.equalsIgnoreCase("")) {
      mountName = pt.getDefaultName(name);
    }

    String path = type + "." + name;
    try {
      ec.getPetConfig().set(path + ".pet.type", pt.toString());
      ec.getPetConfig().set(path + ".pet.name", petName);

      for (PetData pd : data) {
        ec.getPetConfig().set(path + ".pet.data." + pd.toString().toLowerCase(), true);
      }

      if (mountData != null && mountType != null) {
        ec.getPetConfig().set(path + ".mount.type", mountType.toString());
        ec.getPetConfig().set(path + ".mount.name", mountName);
        for (PetData pd : mountData) {
          ec.getPetConfig().set(path + ".mount.data." + pd.toString().toLowerCase(), true);
        }
      }
    } catch (Exception e) {
    }
    ec.getPetConfig().saveConfig();
  }
Exemplo n.º 8
0
  public LivingPet createPetFromFile(String type, Player p) {
    if ((Boolean) ec.options.getConfigOption("loadSavedPets", true)) {
      String path = type + "." + p.getName();
      if (ec.getPetConfig().get(path) != null) {
        PetType petType = PetType.valueOf(ec.getPetConfig().getString(path + ".pet.type"));
        String name = ec.getPetConfig().getString(path + ".pet.name");
        if (name.equalsIgnoreCase("") || name == null) {
          name = petType.getDefaultName(p.getName());
        }
        if (petType == null) return null;
        if (!ec.options.allowPetType(petType)) {
          return null;
        }
        LivingPet pi = this.createPet(p, petType, true);
        if (pi == null) {
          return null;
        }
        // Pet pi = petType.getNewPetInstance(p, petType);
        // Pet pi = new Pet(p, petType);

        pi.setName(name);

        ArrayList<PetData> data = new ArrayList<PetData>();
        ConfigurationSection cs = ec.getPetConfig().getConfigurationSection(path + ".pet.data");
        if (cs != null) {
          for (String key : cs.getKeys(false)) {
            if (EnumUtil.isEnumType(PetData.class, key.toUpperCase())) {
              PetData pd = PetData.valueOf(key.toUpperCase());
              data.add(pd);
            } else {
              Logger.log(
                  Logger.LogLevel.WARNING,
                  "Error whilst loading data Pet Save Data for "
                      + pi.getOwner().getName()
                      + ". Unknown enum type: "
                      + key
                      + ".",
                  true);
            }
          }
        }

        if (!data.isEmpty()) {
          setData(pi, data.toArray(new PetData[data.size()]), true);
        }

        if (ec.getPetConfig().get(path + ".mount.type") != null) {
          PetType mountPetType = PetType.valueOf(ec.getPetConfig().getString(path + ".mount.type"));
          String mountName = ec.getPetConfig().getString(path + ".mount.name");
          if (mountName.equalsIgnoreCase("") || mountName == null) {
            mountName = mountPetType.getDefaultName(p.getName());
          }
          if (mountPetType == null) return null;
          if (ec.options.allowMounts(petType)) {
            LivingPet mount = pi.createMount(mountPetType, true);
            if (mount != null) {
              mount.setName(mountName);
              ArrayList<PetData> mountData = new ArrayList<PetData>();
              ConfigurationSection mcs =
                  ec.getPetConfig().getConfigurationSection(path + ".mount.data");
              if (mcs != null) {
                for (String key : mcs.getKeys(false)) {
                  if (EnumUtil.isEnumType(PetData.class, key.toUpperCase())) {
                    PetData pd = PetData.valueOf(key.toUpperCase());
                    data.add(pd);
                  } else {
                    Logger.log(
                        Logger.LogLevel.WARNING,
                        "Error whilst loading data Pet Mount Save Data for "
                            + pi.getOwner().getName()
                            + ". Unknown enum type: "
                            + key
                            + ".",
                        true);
                  }
                }
              }
              if (!mountData.isEmpty()) {
                setData(pi, mountData.toArray(new PetData[mountData.size()]), true);
              }
            }
          }
        }

        forceAllValidData(pi);
        return pi;
      }
    }
    return null;
  }