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(); }
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; }
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(); }
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(); }
public void setData(LivingPet pet, PetData pd, boolean b) { PetType petType = pet.getPetType(); if (petType.isDataAllowed(pd)) { if (pd == PetData.BABY) { if (petType == PetType.ZOMBIE) { ((ZombiePet) pet).setBaby(b); } else if (petType == PetType.PIGZOMBIE) { ((PigZombiePet) pet).setBaby(b); } else { ((IAgeablePet) pet).setBaby(b); } } if (pd == PetData.POWER) { ((CreeperPet) pet).setPowered(b); } if (pd.isType(PetData.Type.SIZE)) { int i = 1; if (pd == PetData.MEDIUM) { i = 2; } else if (pd == PetData.LARGE) { i = 4; } if (petType == PetType.SLIME) { ((SlimePet) pet).setSize(i); } if (petType == PetType.MAGMACUBE) { ((MagmaCubePet) pet).setSize(i); } } if (pd.isType(PetData.Type.CAT) && petType == PetType.OCELOT) { try { org.bukkit.entity.Ocelot.Type t = org.bukkit.entity.Ocelot.Type.valueOf( pd.toString() + (pd == PetData.WILD ? "_OCELOT" : "_CAT")); if (t != null) { ((OcelotPet) pet).setCatType(t); } } catch (Exception e) { Logger.log( Logger.LogLevel.SEVERE, "Encountered exception whilst attempting to convert PetData to Ocelot.Type.", e, true); } } if (pd == PetData.ANGRY) { ((WolfPet) pet).setAngry(b); } if (pd == PetData.TAMED) { ((WolfPet) pet).setTamed(b); } if (pd.isType(PetData.Type.PROF)) { Profession p = Profession.valueOf(pd.toString()); if (p != null) { ((VillagerPet) pet).setProfession(p); } } if (pd.isType(PetData.Type.COLOUR) && (petType == PetType.SHEEP || petType == PetType.WOLF)) { String s = pd == PetData.LIGHTBLUE ? "LIGHT_BLUE" : pd.toString(); try { DyeColor dc = DyeColor.valueOf(s); if (dc != null) { if (petType == PetType.SHEEP) { ((SheepPet) pet).setColor(dc); } else if (petType == PetType.WOLF) { ((WolfPet) pet).setCollarColor(dc); } } } catch (Exception e) { Logger.log( Logger.LogLevel.SEVERE, "Encountered exception whilst attempting to convert PetData to DyeColor.", e, true); } } if (pd == PetData.WITHER) { ((SkeletonPet) pet).setWither(b); } if (pd == PetData.VILLAGER) { if (petType == PetType.ZOMBIE) { ((ZombiePet) pet).setVillager(b); } else if (petType == PetType.PIGZOMBIE) { ((PigZombiePet) pet).setVillager(b); } } if (pd == PetData.FIRE) { ((BlazePet) pet).setOnFire(b); } if (pd == PetData.SADDLE) { if (petType == PetType.PIG) { ((PigPet) pet).setSaddle(b); } else if (petType == PetType.HORSE) { ((HorsePet) pet).setSaddled(b); } } if (pd == PetData.SHEARED) { ((SheepPet) pet).setSheared(b); } if (pd == PetData.SCREAMING) { ((EndermanPet) pet).setScreaming(b); } if (pd == PetData.SHIELD) { ((WitherPet) pet).setShielded(b); } if (petType == PetType.HORSE) { if (pd == PetData.CHESTED) { ((HorsePet) pet).setChested(b); } if (pd.isType(PetData.Type.HORSE_TYPE)) { try { HorseType h = HorseType.valueOf(pd.toString()); if (h != null) { ((HorsePet) pet).setHorseType(h); } } catch (Exception e) { Logger.log( Logger.LogLevel.WARNING, "Encountered exception whilst attempting to convert PetData to Horse.Type.", e, true); } } if (pd.isType(PetData.Type.HORSE_VARIANT)) { try { HorseVariant v = HorseVariant.valueOf(pd.toString()); if (v != null) { HorseMarking m = ((HorsePet) pet).getMarking(); if (m == null) { m = HorseMarking.NONE; } ((HorsePet) pet).setVariant(v, m); } } catch (Exception e) { Logger.log( Logger.LogLevel.WARNING, "Encountered exception whilst attempting to convert PetData to Horse.Variant.", e, true); } } if (pd.isType(PetData.Type.HORSE_MARKING)) { try { HorseMarking m; if (pd == PetData.WHITEPATCH) { m = HorseMarking.WHITE_PATCH; } else if (pd == PetData.WHITESPOT) { m = HorseMarking.WHITE_SPOTS; } else if (pd == PetData.BLACKSPOT) { m = HorseMarking.BLACK_SPOTS; } else { m = HorseMarking.valueOf(pd.toString()); } if (m != null) { HorseVariant v = ((HorsePet) pet).getVariant(); if (v == null) { v = HorseVariant.WHITE; } ((HorsePet) pet).setVariant(v, m); } } catch (Exception e) { Logger.log( Logger.LogLevel.WARNING, "Encountered exception whilst attempting to convert PetData to Horse.Marking.", e, true); } } if (pd.isType(PetData.Type.HORSE_ARMOUR)) { try { HorseArmour a; if (pd == PetData.NOARMOUR) { a = HorseArmour.NONE; } else { a = HorseArmour.valueOf(pd.toString()); } if (a != null) { ((HorsePet) pet).setArmour(a); } } catch (Exception e) { Logger.log( Logger.LogLevel.WARNING, "Encountered exception whilst attempting to convert PetData to Horse.Armour.", e, true); } } } ListIterator<PetData> i = pet.getActiveData().listIterator(); while (i.hasNext()) { PetData petData = i.next(); if (petData != pd) { ListIterator<PetData.Type> i2 = pd.getTypes().listIterator(); while (i2.hasNext()) { PetData.Type type = i2.next(); if (type != PetData.Type.BOOLEAN && petData.isType(type)) { i.remove(); break; } } } } if (b) { if (!pet.getActiveData().contains(pd)) { pet.getActiveData().add(pd); } } else { if (pet.getActiveData().contains(pd)) { pet.getActiveData().remove(pd); } } } }
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; }