Example #1
0
  @SuppressWarnings("javadoc")
  @Deprecated
  public short parseDurability(final String string, final Material material) {
    try {
      return Short.parseShort(string);
    } catch (final NumberFormatException e) {
    }

    final String s = string.replace(' ', '_').toUpperCase();
    MaterialData data = null;

    try {
      switch (material) {
        case COAL:
          data = new Coal(CoalType.valueOf(s));
          break;
        case WOOD:
        case LOG:
          data = new Tree(TreeSpecies.valueOf(s));
          break;
        case LEAVES:
          data = new Leaves(TreeSpecies.valueOf(s));
          break;
        case STEP:
        case DOUBLE_STEP:
          data = new Step(Material.valueOf(s));
          break;
        case INK_SACK:
          data = new Dye();
          ((Dye) data).setColor(DyeColor.valueOf(s));
          break;
        case WOOL:
          data = new Wool(DyeColor.valueOf(s));
          break;
        case MONSTER_EGGS:
          data = new MonsterEggs(Material.valueOf(s));
          break;
        case SMOOTH_BRICK:
          data = new SmoothBrick(Material.valueOf(s));
          break;
        case SANDSTONE:
          data = new Sandstone(Material.valueOf(s));
      }
    } catch (final IllegalArgumentException e) {
    }

    return data == null ? 0 : (short) data.getData();
  } // */
  public static short getAnyDataShort(String objectString, String enumValue)
      throws IllegalArgumentException {
    // Firstly, can the string be cast directly as a short?
    try {
      Short s = Short.parseShort(enumValue);
      return s;
    } catch (NumberFormatException ex) {
    }

    // If not, test the enum
    if (objectString.equalsIgnoreCase("LOG")
        || objectString.equalsIgnoreCase("LEAVES")
        || objectString.equalsIgnoreCase("SAPLING")) {
      return (short) TreeSpecies.valueOf(enumValue).getData();
    } else if (objectString.equalsIgnoreCase("WOOL")
        || objectString.equalsIgnoreCase("CREATURE_SHEEP")) {
      return (short) DyeColor.valueOf(enumValue).getData();
    } else if (objectString.equalsIgnoreCase("INK_SACK")) {
      return (short) (0xF - DyeColor.valueOf(enumValue).getData());
    } else if (objectString.equalsIgnoreCase("COAL")) {
      return (short) (CoalType.valueOf(enumValue).getData());
    } else if (objectString.equalsIgnoreCase("CROPS")) {
      return (short) (CropState.valueOf(enumValue).getData());
    } else if (objectString.equalsIgnoreCase("STEP")
        || objectString.equalsIgnoreCase("DOUBLE_STEP")) {
      if (enumValue.equalsIgnoreCase("STONE")) return 0;
      else if (enumValue.equalsIgnoreCase("SANDSTONE")) return 1;
      else if (enumValue.equalsIgnoreCase("WOOD")) return 2;
      else if (enumValue.equalsIgnoreCase("COBBLESTONE")) return 3;
      else throw new IllegalArgumentException();
    } else if (objectString.equalsIgnoreCase("CREATURE_PIG")) {
      if (enumValue.equalsIgnoreCase("UNSADDLED")) return 0;
      else if (enumValue.equalsIgnoreCase("SADDLED")) return 1;
      else throw new IllegalArgumentException();
    } else if (objectString.equalsIgnoreCase("CREATURE_CREEPER")) {
      if (enumValue.equalsIgnoreCase("UNPOWERED")) return 0;
      else if (enumValue.equalsIgnoreCase("POWERED")) return 1;
      else throw new IllegalArgumentException();
    } else if (objectString.equalsIgnoreCase("CREATURE_WOLF")) {
      if (enumValue.equalsIgnoreCase("NEUTRAL")) return 0;
      else if (enumValue.equalsIgnoreCase("TAME")) return 1;
      else if (enumValue.equalsIgnoreCase("TAMED")) return 1;
      else if (enumValue.equalsIgnoreCase("ANGRY")) return 2;
      else throw new IllegalArgumentException();
    } else if (objectString.equalsIgnoreCase("CREATURE_SLIME")) {
      if (enumValue.equalsIgnoreCase("TINY")) return 1;
      else if (enumValue.equalsIgnoreCase("SMALL")) return 2;
      else if (enumValue.equalsIgnoreCase("BIG")) return 3;
      else if (enumValue.equalsIgnoreCase("HUGE")) return 4;
      else throw new IllegalArgumentException();
    } else {
      return 0;
    }
  }