Пример #1
0
  public ItemStack matchItem(String name) {
    int id = 0;
    int dmg = 0;
    String dataName = null;

    if (name.contains(":")) {
      String[] parts = name.split(":");
      dataName = parts[1];
      name = parts[0];
    }
    try {
      id = Integer.parseInt(name);
      Material valid = Material.getMaterial(id);
      if (valid == null) {
        return null;
      }
    } catch (NumberFormatException e) {
      Material type = Material.getMaterial(name.toUpperCase());

      if (type == null) {
        return null;
      }

      id = type.getId();
    }

    if (dataName != null) {
      dmg = matchItemData(id, dataName);

      if (dmg < 1) {
        return null;
      }
    }

    return new ItemStack(id, 1, (short) dmg);
  }
Пример #2
0
  public static int matchItemData(int id, String filter) {
    // Missing some key code, need to be finished sometime in future.
    try {
      return Integer.parseInt(filter);
    } catch (NumberFormatException ignored) {

    }

    if (Material.WOOD.getId() == id) {
      for (TreeSpecies search : TreeSpecies.values()) {
        if (filter.equalsIgnoreCase(search.toString())) {
          return search.getData();
        }
      }

      return 0;
    } else if (Material.WOOL.getId() == id) {
      for (DyeColor search : DyeColor.values()) {
        if (filter.equalsIgnoreCase(search.toString())) {
          return search.getWoolData();
        }
      }

      return 0;
    } else if (Material.INK_SACK.getId() == id) {
      for (DyeColor search : DyeColor.values()) {
        if (filter.equalsIgnoreCase(search.toString())) {
          return search.getDyeData();
        }
      }

      return 0;
    } else if (Material.STEP.getId() == id) {
      Step s = new Step();
      for (Material search : s.getTextures()) {
        if (filter.equalsIgnoreCase(search.toString())) {
          return s.getTextures().indexOf(search);
        }
      }

      return 0;
    } else if (Material.DOUBLE_STEP.getId() == id) {
      Step s = new Step();
      for (Material search : s.getTextures()) {
        if (filter.equalsIgnoreCase(search.toString())) {
          return s.getTextures().indexOf(search);
        }
      }

      return 0;
    } else if (Material.SMOOTH_BRICK.getId() == id) {
      SmoothBrick s = new SmoothBrick();
      for (Material search : s.getTextures()) {
        if (filter.equalsIgnoreCase(search.toString())) {
          return s.getTextures().indexOf(search);
        }
      }

      return 0;
    }

    return 0;
  }