@Override
 public String toString() {
   String val = "";
   if (type != null) {
     val += "!!" + type.name();
   }
   val += leData.toString();
   return val;
 }
  public static CreatureData parseFromString(String state) {
    SkeletonType type = null;
    LivingEntityData leData = (LivingEntityData) LivingEntityData.parseFromString(state);

    if (!state.isEmpty() && !state.equals("0")) {
      String split[] = state.split(OtherDropsConfig.CreatureDataSeparator);

      for (String sub : split) {
        sub = sub.toLowerCase().replaceAll("[\\s-_]", "");
        for (SkeletonType sType : SkeletonType.values()) {
          if (CommonMaterial.fuzzyMatchString(sType.toString(), sub)) {
            type = sType;
          }
        }
      }
    }

    return new SkeletonData(type, leData);
  }
Example #3
0
  protected SpellResult alterEntity(Entity entity) {
    EntityType entityType = entity.getType();
    switch (entityType) {
      case PAINTING:
        registerModified(entity);
        Painting painting = (Painting) entity;
        Art[] artValues = Art.values();
        Art oldArt = painting.getArt();
        Art newArt = oldArt;
        int ordinal = (oldArt.ordinal() + 1);
        for (int i = 0; i < artValues.length; i++) {
          newArt = artValues[ordinal++ % artValues.length];
          painting.setArt(newArt);
          newArt = painting.getArt();
          if (oldArt != newArt) {
            break;
          }
        }
        if (oldArt == newArt) {
          return SpellResult.FAIL;
        }
        mage.sendDebugMessage("Altering art from " + oldArt + " to " + newArt);
        break;
      case ITEM_FRAME:
        ItemFrame itemFrame = (ItemFrame) entity;
        ItemStack frameItem = itemFrame.getItem();
        if (frameItem == null || frameItem.getType() != Material.MAP) {
          return SpellResult.NO_TARGET;
        }
        short data = frameItem.getDurability();
        data++;
        MapView mapView = DeprecatedUtils.getMap(data);
        if (mapView == null) {
          data = 0;
          mapView = DeprecatedUtils.getMap(data);
          if (mapView == null) {
            return SpellResult.NO_TARGET;
          }
        }
        registerModified(entity);
        frameItem.setDurability(data);
        itemFrame.setItem(frameItem);
        break;
      case HORSE:
        registerModified(entity);
        Horse horse = (Horse) entity;

        Color color = horse.getColor();
        Color[] colorValues = Color.values();
        color = colorValues[(color.ordinal() + 1) % colorValues.length];

        Variant variant = horse.getVariant();
        Variant[] variantValues = Variant.values();
        variant = variantValues[(variant.ordinal() + 1) % variantValues.length];

        Style horseStyle = horse.getStyle();
        Style[] styleValues = Style.values();
        horseStyle = styleValues[(horseStyle.ordinal() + 1) % styleValues.length];

        horse.setStyle(horseStyle);
        horse.setColor(color);
        horse.setVariant(variant);
        break;
      case OCELOT:
        registerModified(entity);
        Ocelot ocelot = (Ocelot) entity;
        Type catType = ocelot.getCatType();
        Type[] typeValues = Type.values();
        catType = typeValues[(catType.ordinal() + 1) % typeValues.length];
        ocelot.setCatType(catType);
        break;
      case VILLAGER:
        registerModified(entity);
        Villager villager = (Villager) entity;
        Profession profession = villager.getProfession();
        Profession[] professionValues = Profession.values();
        profession = professionValues[(profession.ordinal() + 1) % professionValues.length];
        villager.setProfession(profession);
        break;
      case WOLF:
        registerModified(entity);
        Wolf wolf = (Wolf) entity;
        DyeColor wolfColor = wolf.getCollarColor();
        DyeColor[] wolfColorValues = DyeColor.values();
        wolfColor = wolfColorValues[(wolfColor.ordinal() + 1) % wolfColorValues.length];
        wolf.setCollarColor(wolfColor);
        break;
      case SHEEP:
        registerModified(entity);
        Sheep sheep = (Sheep) entity;
        DyeColor dyeColor = sheep.getColor();
        DyeColor[] dyeColorValues = DyeColor.values();
        dyeColor = dyeColorValues[(dyeColor.ordinal() + 1) % dyeColorValues.length];
        sheep.setColor(dyeColor);
        break;
      case SKELETON:
        registerModified(entity);
        Skeleton skeleton = (Skeleton) entity;
        SkeletonType skeletonType = skeleton.getSkeletonType();
        SkeletonType[] skeletonTypeValues = SkeletonType.values();
        skeletonType = skeletonTypeValues[(skeletonType.ordinal() + 1) % skeletonTypeValues.length];
        skeleton.setSkeletonType(skeletonType);
        break;
      default:
        return SpellResult.NO_TARGET;
    }
    ;
    registerForUndo();
    return SpellResult.CAST;
  }
Example #4
0
 static {
   skeletonTypes = new HashMap<>();
   for (final SkeletonType e : SkeletonType.values()) {
     skeletonTypes.put(e.name(), e);
   }
 }
Example #5
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;
  }
Example #6
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",
        };
  }