Esempio n. 1
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;
  }
Esempio n. 2
0
  static {
    TYPE = FlagType.SUMMON;

    A =
        new String[] {
          "{flag} <type> | [arguments]",
        };

    String argFormat = "  %-26s = %s";

    D =
        new String[] {
          "Summons a creature.",
          "Using this flag more than once will add more creatures.",
          "",
          "The <type> argument can be a living entity type, you can find all entity types in '"
              + Files.FILE_INFO_NAMES
              + "' file.",
          "",
          "Optionally you can add some arguments separated by | character, those being:",
          String.format(argFormat, "noeffect", "no spawning particle effects on creature."),
          String.format(
              argFormat, "noremove", "prevents creature from being removed if nobody is near it."),
          String.format(
              argFormat,
              "mountnext",
              "this creature will mount the next creature definition that triggers after it."),
          String.format(
              argFormat,
              "chance <0.01-100>%",
              "chance of the creature to spawn, this value is for individual creatures."),
          String.format(argFormat, "num <number>", "spawn more cloned creatures."),
          String.format(
              argFormat,
              "spread <range>",
              "spawns creature(s) spread within block range instead of on top of workbench or furnace. (WARNING: can be CPU intensive)"),
          String.format(
              argFormat,
              "target",
              "creature targets crafter, that means monsters attack and animals follow and the rest do nothing"),
          String.format(
              argFormat,
              "hit",
              "crafter will fake-attack the creature to provoke it into attacking or scare it away."),
          String.format(
              argFormat,
              "onfire <time>",
              "spawn creature on fire for <time> amount of seconds, value can be float."),
          String.format(
              argFormat, "pickup [true/false]", "change if creature can pick-up dropped items."),
          String.format(
              argFormat,
              "pet [nosit]",
              "makes creature owned by crafter, only works for wolf and ocelot, optionally specify 'nosit' to not spawn creature in sit stance."),
          String.format(
              argFormat,
              "angry",
              "makes creature angry, only works for wolves and pigzombies; you can't use 'pet' with this."),
          String.format(
              argFormat,
              "cat <type>",
              "ocelot type, available values: "
                  + Tools.collectionToString(Arrays.asList(Ocelot.Type.values())).toLowerCase()),
          String.format(
              argFormat,
              "saddle [mount]",
              "adds saddle on creature, only works for pig, optionally you can specify 'mount' to make crafter mount creature."),
          String.format(
              argFormat,
              "color <dye>",
              "sets the color of animal, only works for sheep and pet wolf; values can be found in '"
                  + Files.FILE_INFO_NAMES
                  + "' file at 'DYE COLORS' section."),
          String.format(
              argFormat, "shearedsheep", "sets the sheep as sheared, only works for sheep."),
          String.format(
              argFormat,
              "villager <type>",
              "set the villager profession, values: "
                  + Tools.collectionToString(Arrays.asList(Villager.Profession.values()))
                      .toLowerCase()),
          String.format(
              argFormat,
              "skeleton <type>",
              "set the skeleton type, values: "
                  + Tools.collectionToString(Arrays.asList(SkeletonType.values())).toLowerCase()),
          String.format(
              argFormat,
              "zombievillager",
              "makes zombie a zombie villager, only works on zombies."),
          String.format(
              argFormat, "poweredcreeper", "makes creeper a powered one, only works for creepers."),
          String.format(argFormat, "playerirongolem", "marks iron golem as player-made."),
          String.format(
              argFormat,
              "name <text>",
              "sets the creature's name, supports colors (<red>, &3, etc)."),
          String.format(
              argFormat, "nohidename", "don't hide name plate when not aiming at creature."),
          String.format(
              argFormat, "hp <health> [max]", "set creature's health and optionally max health"),
          String.format(
              argFormat,
              "baby",
              "spawn creature as a baby, works with animals, villagers and zombies."),
          String.format(
              argFormat,
              "agelock",
              "prevent the creature from maturing or getting ready for mating, works with animals and villagers."),
          String.format(
              argFormat,
              "nobreed",
              "prevent the creature being able to breed, works for animals and villagers."),
          String.format(
              argFormat,
              "head <item> [drop%]",
              "equip an item on the creature's head with optional drop chance."),
          String.format(
              argFormat,
              "chest <item> [drop%]",
              "equip an item on the creature's chest with optional drop chance."),
          String.format(
              argFormat,
              "legs <item> [drop%]",
              "equip an item on the creature's legs with optional drop chance."),
          String.format(
              argFormat,
              "feet <item> [drop%]",
              "equip an item on the creature's feet with optional drop chance."),
          String.format(
              argFormat,
              "hand <item> [drop%]",
              "equip an item on the creature's hand with optional drop chance; for enderman it only uses material and data from the item."),
          String.format(
              argFormat,
              "potion <type> [time] [amp]",
              "adds potion effect on the spawned creature; for <type> see '"
                  + Files.FILE_INFO_NAMES
                  + "' at 'POTION EFFECT TYPE'; [time] can be a decimal of duration in seconds; [amp] can be an integer that defines amplifier; this argument can be used more than once to add more effects."),
          "",
          "These arguments can be used in any order and they're all optional.",
        };

    E =
        new String[] {
          "{flag} cow",
          "{flag} skeleton | hand bow // skeletons spawn without weapons, you need to give it one",
          "{flag} zombie | zombievillager | baby | chest chainmail_chestplate 25% | legs chainmail_leggings 25% | hand iron_sword 50% // baby villager zombie warrior",
          "{flag} sheep | color pink | name <light_purple>Pony",
          "{flag} ocelot | cat redcat | pet | potion speed 30 5",
          "// chicken on a villager and villager on a cow:",
          "{flag} chicken | mountnext",
          "{flag} villager | mountnext",
          "{flag} cow",
        };
  }
Esempio n. 3
0
 public void setName(String name) {
   this.name = Tools.parseColors(name, false);
 }
Esempio n. 4
0
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length > 0) {
      String name = (sender instanceof Player ? sender.getName() : null);

      boolean next = args[0].equalsIgnoreCase("next");

      if (next || args[0].equalsIgnoreCase("prev")) {
        Pages pages = pagination.get(name);

        if (pages != null) {
          if (next ? pages.hasNext() : pages.hasPrev()) {
            String page = (next ? pages.next() : pages.prev());
            Messages.CMD_RECIPES_HEADER.print(
                sender,
                null,
                "{item}",
                Tools.Item.print(pages.item),
                "{num}",
                (pages.page + 1),
                "{total}",
                pages.pages.length);
            Messages.send(sender, page);

            if (pages.hasNext()) {
              Messages.CMD_RECIPES_MORE.print(
                  sender,
                  null,
                  "{cmdnext}",
                  "/" + label + " next",
                  "{cmdprev}",
                  "/" + label + " prev");
            } else {
              Messages.CMD_RECIPES_END.print(sender);
            }
          } else {
            if (next) {
              Messages.CMD_RECIPES_NONEXT.print(sender, null, "{command}", "/" + label + " prev");
            } else {
              Messages.CMD_RECIPES_NOPREV.print(sender, null, "{command}", "/" + label + " next");
            }
          }
        } else {
          Messages.CMD_RECIPES_NEEDQUERY.print(sender);
        }
      } else {
        ItemStack item;

        if (args[0].equalsIgnoreCase("this")) {
          if (sender instanceof Player) {
            Player player = (Player) sender;
            item = player.getItemInHand();

            if (item == null) {
              Messages.CMD_RECIPES_NOHAND.print(sender);
              return true;
            }
          } else {
            sender.sendMessage("The 'this' argument can't be used from console.");
            return true;
          }
        } else {
          item =
              Tools.parseItem(args[0], Vanilla.DATA_WILDCARD, ParseBit.NO_META | ParseBit.NO_PRINT);

          if (item == null) {
            Messages.CMD_RECIPES_INVALIDITEM.print(sender, null, "{arg}", args[0]);
            return true;
          }
        }

        boolean ingredient = (args.length > 1 && args[1].charAt(0) == 'i');

        List<String> list = new ArrayList<String>();

        for (Entry<BaseRecipe, RecipeInfo> e :
            RecipeManager.getRecipes().getRecipeList().entrySet()) {
          BaseRecipe recipe = e.getKey();

          if (hasItem(recipe, item, ingredient)) {
            list.add(recipe.printChat());
          }
        }

        if (!list.isEmpty()) {
          Pages pages = new Pages(name, item, list);
          pagination.put(name, pages);

          Messages.CMD_RECIPES_HEADER.print(
              sender,
              null,
              "{item}",
              Tools.Item.print(pages.item),
              "{num}",
              1,
              "{total}",
              pages.pages.length);
          Messages.send(sender, pages.next());

          if (pages.hasNext()) {
            Messages.CMD_RECIPES_MORE.print(
                sender,
                null,
                "{cmdnext}",
                "/" + label + " next",
                "{cmdprev}",
                "/" + label + " prev");
          } else {
            Messages.CMD_RECIPES_END.print(sender);
          }
        } else {
          Messages.CMD_RECIPES_NORESULTS.print(sender, null, "{item}", Tools.Item.print(item));
        }
      }
    } else {
      int mc = 0;
      int rm = 0;
      int other = 0;

      for (RecipeInfo info : RecipeManager.getRecipes().getRecipeList().values()) {
        switch (info.getOwner()) {
          case MINECRAFT:
            {
              mc++;
              break;
            }

          case RECIPEMANAGER:
            {
              rm++;
              break;
            }

          default:
            {
              other++;
            }
        }
      }

      Messages.CMD_RECIPES_USAGE.print(sender, null, "{command}", label);
      Messages.CMD_RECIPES_STATS_MC.print(sender, null, "{num}", mc);
      Messages.CMD_RECIPES_STATS_RM.print(sender, null, "{num}", rm);
      Messages.CMD_RECIPES_STATS_OTHER.print(sender, null, "{num}", other);
    }

    return true;
  }