Ejemplo n.º 1
0
  @Override
  public ShapedRecipe matchShapedRecipe(List<List<Material>> materials) {
    Set<Material> set = new HashSet<Material>();
    List<List<Material>> list = new ArrayList<List<Material>>();
    List<List<Material>> parentList = new ArrayList<List<Material>>();
    for (List<Material> materialsRow : materials) {
      List<Material> parentRow = new ArrayList<Material>();
      List<Material> row = new ArrayList<Material>();
      for (Material m : materialsRow) {
        row.add(m);
        Material parent = m;
        if (m != null) {
          set.add(m);
          if (m.isSubMaterial()) {
            parent = m.getParentMaterial();
          }
        }
        parentRow.add(parent);
      }
      parentList.add(parentRow);
      list.add(row);
    }

    if (!allShapedRecipes.containsKey(set.size())) {
      return null;
    }
    ShapedRecipe recipe = allShapedRecipes.get(set.size()).matchShapedRecipe(list, true);
    if (recipe == null) {
      recipe = allShapedRecipes.get(set.size()).matchShapedRecipe(parentList, false);
    }
    return recipe;
  }
Ejemplo n.º 2
0
  @Override
  public ShapelessRecipe matchShapelessRecipe(Plugin plugin, List<Material> materials) {
    Set<Material> unique = new HashSet<Material>();
    List<Material> parentList = new ArrayList<Material>();
    for (Material m : materials) {
      if (m.isSubMaterial()) {
        m = m.getParentMaterial();
      }
      parentList.add(m);
    }
    unique.addAll(parentList);
    unique.removeAll(Collections.singletonList(null));

    ShapelessRecipe recipe = null;
    if (registeredShapelessRecipes.containsKey(plugin)
        && registeredShapelessRecipes.get(plugin).containsKey(unique.size())) {
      for (ShapelessRecipe r : registeredShapelessRecipes.get(plugin).get(unique.size())) {
        if (r.getIncludeData()) {
          List<Material> materialsCopy = new ArrayList<Material>(materials);
          List<Material> ingredientsCopy = new ArrayList<Material>(r.getIngredients());
          Collections.sort(materialsCopy, new MaterialComparable());
          Collections.sort(ingredientsCopy, new MaterialComparable());
          if (materialsCopy.equals(ingredientsCopy)) {
            recipe = r;
            break;
          }
        } else {
          List<Material> parentsCopy = new ArrayList<Material>(parentList);
          List<Material> ingredientsCopy = new ArrayList<Material>(r.getIngredients());
          Collections.sort(parentsCopy, new MaterialComparable());
          Collections.sort(ingredientsCopy, new MaterialComparable());
          if (parentsCopy.equals(ingredientsCopy)) {
            recipe = r;
            break;
          }
        }
      }
    }
    if (recipe == null) {
      recipe = matchShapelessRecipe(materials);
    }

    return recipe;
  }