예제 #1
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;
  }