/** Clears and then populates plugin's socket list; also adds identification tome */
 public void build() {
   List<String> l = plugin.getConfig().getStringList("SocketItem.Items");
   for (String name : l) {
     for (Material mat : plugin.getItemAPI().allItems()) {
       FurnaceRecipe recipe =
           new FurnaceRecipe(new ItemStack(mat), Material.valueOf(name.toUpperCase()));
       recipe.setInput(mat);
       plugin.getServer().addRecipe(recipe);
     }
   }
 }
Example #2
0
  private static boolean match(Recipe recipe1, Recipe recipe2) {
    if (recipe1 instanceof ShapedRecipe) {
      if (recipe2 instanceof ShapedRecipe == false) {
        return false; // if other recipe is not the same type then they're not equal.
      }

      ShapedRecipe r1 = (ShapedRecipe) recipe1;
      ShapedRecipe r2 = (ShapedRecipe) recipe2;

      // convert both shapes and ingredient maps to common ItemStack array.
      ItemStack[] matrix1 = shapeToMatrix(r1.getShape(), r1.getIngredientMap());
      ItemStack[] matrix2 = shapeToMatrix(r2.getShape(), r2.getIngredientMap());

      if (!Arrays.equals(
          matrix1,
          matrix2)) // compare arrays and if they don't match run another check with one shape
                    // mirrored.
      {
        mirrorMatrix(matrix1);

        return Arrays.equals(matrix1, matrix2);
      }

      return true; // ingredients match.
    } else if (recipe1 instanceof ShapelessRecipe) {
      if (recipe2 instanceof ShapelessRecipe == false) {
        return false; // if other recipe is not the same type then they're not equal.
      }

      ShapelessRecipe r1 = (ShapelessRecipe) recipe1;
      ShapelessRecipe r2 = (ShapelessRecipe) recipe2;

      // get copies of the ingredient lists
      List<ItemStack> find = r1.getIngredientList();
      List<ItemStack> compare = r2.getIngredientList();

      if (find.size() != compare.size()) {
        return false; // if they don't have the same amount of ingredients they're not equal.
      }

      for (ItemStack item : compare) {
        if (!find.remove(item)) {
          return false; // if ingredient wasn't removed (not found) then they're not equal.
        }
      }

      return find.isEmpty(); // if there are any ingredients not removed then they're not equal.
    } else if (recipe1 instanceof FurnaceRecipe) {
      if (recipe2 instanceof FurnaceRecipe == false) {
        return false; // if other recipe is not the same type then they're not equal.
      }

      FurnaceRecipe r1 = (FurnaceRecipe) recipe1;
      FurnaceRecipe r2 = (FurnaceRecipe) recipe2;

      // return (r1.getInput().equals(r2.getInput())); // TODO use this when furnace data PR is
      // pulled
      return r1.getInput().getTypeId() == r2.getInput().getTypeId();
    } else {
      throw new IllegalArgumentException(
          "Unsupported recipe type: '" + recipe1 + "', update this class!");
    }
  }