Exemplo n.º 1
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.º 2
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.º 3
0
  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);
        }
      }
    }
  }
Exemplo n.º 4
0
 public void setData(LivingPet pet, PetData[] data, boolean b) {
   PetType petType = pet.getPetType();
   for (PetData pd : data) {
     setData(pet, pd, b);
   }
 }