Ejemplo n.º 1
0
    public void setNum(int num) {
      if (num < 1) {
        this.num = 1;

        ErrorReporter.warning(
            "The " + getType() + " flag can't have 'num' argument less than 1, set to 1.");
      } else {
        this.num = num;
      }
    }
Ejemplo n.º 2
0
    public void setChance(float chance) {
      if (chance < 0.01f || chance > 100.0f) {
        this.chance = Math.min(Math.max(chance, 0.01f), 100.0f);

        ErrorReporter.warning(
            "Flag "
                + getType()
                + " has chance value less than 0.01 or higher than 100.0, value trimmed.");
      } else {
        this.chance = chance;
      }
    }
Ejemplo n.º 3
0
  @Override
  protected boolean onParse(String value) {
    String[] split = value.split("\\|");

    value = split[0].trim();
    EntityType type = Tools.parseEnum(value, EntityType.values());

    if (type == null || !type.isAlive()) {
      ErrorReporter.error(
          "The " + getType() + " flag has invalid creature: " + value,
          "Look in '" + Files.FILE_INFO_NAMES + "' at 'ENTITY TYPES' section for ALIVE entities.");
      return false;
    }

    Customization c = new Customization(type);

    if (split.length > 1) {
      for (int n = 1; n < split.length; n++) {
        String original = split[n].trim();
        value = original.toLowerCase();

        if (value.equals("noremove")) {
          c.setNoRemove(true);
        } else if (value.equals("noeffect")) {
          c.setNoEffect(true);
        } else if (value.equals("target")) {
          c.setTarget(true);
        } else if (value.equals("nohidename")) {
          c.setNoHideName(true);
        } else if (value.equals("mountnext")) {
          c.setMountNext(true);
        } else if (value.equals("angry")) {
          switch (type) {
            case WOLF:
            case PIG_ZOMBIE:
              break;

            default:
              ErrorReporter.warning("Flag " + getType() + " has 'angry' on unsupported creature!");
              continue;
          }

          c.setAngry(true);
        } else if (value.equals("shearedsheep")) {
          if (type != EntityType.SHEEP) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'shearedsheep' on non-sheep creature!");
            continue;
          }

          c.setShearedSheep(true);
        } else if (value.equals("zombievillager")) {
          if (type != EntityType.ZOMBIE) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'zombievillager' on non-zombie creature!");
            continue;
          }

          c.setZombieVillager(true);
        } else if (value.equals("poweredcreeper")) {
          if (type != EntityType.CREEPER) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'poweredcreeper' on non-creeper creature!");
            continue;
          }

          c.setPoweredCreeper(true);
        } else if (value.equals("playerirongolem")) {
          if (type != EntityType.IRON_GOLEM) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'playerirongolem' on non-irongolem creature!");
            continue;
          }

          c.setPlayerIronGolem(true);
        } else if (value.equals("hit")) {
          c.setHit(true);
        } else if (value.equals("baby")) {
          switch (type) {
            case CHICKEN:
            case COW:
            case MUSHROOM_COW:
            case OCELOT:
            case PIG:
            case SHEEP:
            case VILLAGER:
            case WOLF:
            case ZOMBIE: // has set/getBaby() but does not implement Ageable
              break;

            default:
              ErrorReporter.warning(
                  "Flag " + getType() + " has 'baby' set on unsupported creature!");
              continue;
          }

          c.setBaby(true);
        } else if (value.equals("agelock")) {
          switch (type) {
            case CHICKEN:
            case COW:
            case MUSHROOM_COW:
            case OCELOT:
            case PIG:
            case SHEEP:
            case VILLAGER:
            case WOLF:
              break;

            default:
              ErrorReporter.warning(
                  "Flag " + getType() + " has 'agelock' set on unsupported creature!");
              continue;
          }

          c.setAgeLock(true);
        } else if (value.equals("nobreed")) {
          switch (type) {
            case CHICKEN:
            case COW:
            case MUSHROOM_COW:
            case OCELOT:
            case PIG:
            case SHEEP:
            case VILLAGER:
            case WOLF:
              break;

            default:
              ErrorReporter.warning(
                  "Flag " + getType() + " has 'nobreed' set on unsupported creature!");
              continue;
          }

          c.setNoBreed(true);
        } else if (value.startsWith("pickup")) {
          value = value.substring("pickup".length()).trim();

          if (value.isEmpty()) {
            c.setPickup(true);
          } else {
            c.setPickup(value.equals("true"));
          }
        } else if (value.startsWith("pet")) {
          switch (type) {
            case WOLF:
            case OCELOT:
              break;

            default:
              ErrorReporter.warning("Flag " + getType() + " has 'pet' on untameable creature!");
              continue;
          }

          c.setPet(true);

          if (value.length() > "pet".length()) {
            value = value.substring("pet".length()).trim();

            if (value.equals("nosit")) {
              c.setNoSit(true);
            } else {
              ErrorReporter.warning(
                  "Flag " + getType() + " has 'pet' argument with unknown value: " + value);
            }
          }
        } else if (value.startsWith("saddle")) {
          if (type != EntityType.PIG) {
            ErrorReporter.warning("Flag " + getType() + " has 'saddle' on non-pig creature!");
            continue;
          }

          c.setSaddle(true);

          if (value.length() > "saddle".length()) {
            value = value.substring("saddle".length()).trim();

            if (value.equals("mount")) {
              c.setMount(true);
            } else {
              ErrorReporter.warning(
                  "Flag " + getType() + " has 'saddle' argument with unknown value: " + value);
            }
          }
        } else if (value.startsWith("chance")) {
          value = value.substring("chance".length()).trim();

          if (value.charAt(value.length() - 1) == '%') {
            value = value.substring(0, value.length() - 1);
          }

          try {
            c.setChance(Float.valueOf(value));
          } catch (NumberFormatException e) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'chance' argument with invalid number: " + value);
            continue;
          }
        } else if (value.startsWith("num")) {
          value = value.substring("num".length()).trim();

          try {
            c.setNum(Integer.valueOf(value));
          } catch (NumberFormatException e) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'num' argument with invalid value number: " + value);
          }
        } else if (value.startsWith("spread")) {
          value = value.substring("spread".length()).trim();

          try {
            c.setSpread(Integer.valueOf(value));
          } catch (NumberFormatException e) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'spread' argument with invalid value number: " + value);
          }
        } else if (value.startsWith("onfire")) {
          value = value.substring("onfire".length()).trim();

          try {
            c.setOnFire(Float.valueOf(value) * 20.0f);
          } catch (NumberFormatException e) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'onfire' argument with invalid value number: " + value);
          }
        } else if (value.startsWith("color")) {
          switch (type) {
            case SHEEP:
            case WOLF:
              break;

            default:
              ErrorReporter.warning("Flag " + getType() + " has 'color' on unsupported creature!");
              continue;
          }

          value = value.substring("color".length()).trim();

          c.setColor(Tools.parseEnum(value, DyeColor.values()));

          if (c.getColor() == null) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'color' argument with invalid dye color: " + value);
          }
        } else if (value.startsWith("villager")) {
          if (type != EntityType.VILLAGER) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'villager' argument on non-villager creature!");
            continue;
          }

          value = value.substring("villager".length()).trim();

          c.setVillager(Tools.parseEnum(value, Villager.Profession.values()));

          if (c.getVillager() == null) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'villager' argument with invalid type: " + value);
          }
        } else if (value.startsWith("skeleton")) {
          if (type != EntityType.SKELETON) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'skeleton' argument on non-skeleton creature!");
            continue;
          }

          value = value.substring("skeleton".length()).trim();

          c.setSkeleton(Tools.parseEnum(value, SkeletonType.values()));

          if (c.getSkeleton() == null) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'skeleton' argument with invalid type: " + value);
          }
        } else if (value.startsWith("cat")) {
          if (type != EntityType.OCELOT) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'cat' argument on non-ocelot creature!");
            continue;
          }

          value = value.substring("cat".length()).trim();

          c.setCat(Tools.parseEnum(value, Ocelot.Type.values()));

          if (c.getCat() == null) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'cat' argument with invalid type: " + value);
          }
        } else if (value.startsWith("name")) {
          value = original.substring("name".length()).trim();

          c.setName(value);
        } else if (value.startsWith("hp")) {
          value = value.substring("hp".length()).trim();

          String[] args = value.split(" ");

          value = args[0].trim();

          try {
            c.setHp(Integer.valueOf(value));
          } catch (NumberFormatException e) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'hp' argument with invalid number: " + value);
            continue;
          }

          if (args.length > 1) {
            value = args[1].trim();

            try {
              c.setMaxHp(Integer.valueOf(value));
            } catch (NumberFormatException e) {
              ErrorReporter.warning(
                  "Flag "
                      + getType()
                      + " has 'hp' argument with invalid number for maxhp: "
                      + value);
              continue;
            }
          }
        } else if (value.startsWith("potion")) {
          value = value.substring("potion".length()).trim();
          String[] args = value.split(" ");
          value = args[0].trim();

          PotionEffectType effect =
              PotionEffectType.getByName(
                  value); // Tools.parseEnum(value, PotionEffectType.values());

          if (effect == null) {
            ErrorReporter.warning(
                "Flag " + getType() + " has 'potion' argument with invalid type: " + value);
            continue;
          }

          float duration = 1;
          int amplifier = 0;

          if (args.length > 1) {
            value = args[1].trim();

            try {
              duration = Float.valueOf(value);
            } catch (NumberFormatException e) {
              ErrorReporter.warning(
                  "Flag "
                      + getType()
                      + " has 'potion' argument with invalid number for duration: "
                      + value);
              continue;
            }
          }

          if (args.length > 2) {
            value = args[2].trim();

            try {
              amplifier = Integer.valueOf(value);
            } catch (NumberFormatException e) {
              ErrorReporter.warning(
                  "Flag "
                      + getType()
                      + " has 'potion' argument with invalid number for amplifier: "
                      + value);
              continue;
            }
          }

          c.addPotionEffect(effect, duration, amplifier);
        } else if (value.startsWith("hand")
            || value.startsWith("hold")
            || value.startsWith("head")
            || value.startsWith("helmet")
            || value.startsWith("chest")
            || value.startsWith("leg")
            || value.startsWith("feet")
            || value.startsWith("boot")) {
          int index = -1;

          switch (value.charAt(0)) {
            case 'h':
              switch (value.charAt(1)) {
                case 'e':
                  index = 0;
                  break;

                case 'o':
                case 'a':
                  index = 4;
                  break;
              }
              break;

            case 'c':
              index = 1;
              break;

            case 'l':
              index = 2;
              break;

            case 'b':
            case 'f':
              index = 3;
              break;
          }

          if (index < 0) {
            ErrorReporter.warning("Flag " + getType() + " has unknown argument: " + value);
            continue;
          }

          int i = value.indexOf(' ');
          String[] args = value.substring(i + 1).trim().split(" ");
          value = args[0].trim();

          ItemStack item = Tools.parseItem(value, 0);

          if (item == null) {
            continue;
          }

          c.getEquip()[index] = item;

          if (args.length > 1) {
            value = args[1].trim();

            if (value.charAt(value.length() - 1) == '%') {
              value = value.substring(0, value.length() - 1);
            }

            try {
              c.getDrop()[index] = Math.min(Math.max(Float.valueOf(value), 0), 100);
            } catch (NumberFormatException e) {
              ErrorReporter.warning(
                  "Flag " + getType() + " has 'chance' argument with invalid number: " + value);
              continue;
            }
          }
        } else {
          ErrorReporter.warning("Flag " + getType() + " has unknown argument: " + value);
        }
      }
    }

    if (type == EntityType.WOLF) {
      if (c.isPet()) {
        if (c.isAngry()) {
          c.setAngry(false);
          ErrorReporter.warning(
              "Flag " + getType() + " has 'angry' with 'pet' on wolf! Argument 'angry' ignored.");
        }
      } else {
        if (c.getColor() != null) {
          c.setColor(null);
          ErrorReporter.warning(
              "Flag " + getType() + " has 'color' argument without wolf being a pet, ignored.");
        }
      }
    }

    addSpawn(c);

    return true;
  }