broken-arrow

Untitled

Sep 26th, 2021
804
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.broken.cheststorage.Crafting;
  2.  
  3. import org.broken.cheststorage.ChestStorage;
  4. import org.broken.cheststorage.util.ItemUtily;
  5. import org.bukkit.Location;
  6. import org.bukkit.Material;
  7. import org.bukkit.inventory.Inventory;
  8. import org.bukkit.inventory.ItemStack;
  9.  
  10. import java.util.*;
  11.  
  12. public class CraftingUtilitycopy {
  13.  
  14.     private static final Map<Location, Map<ItemStack, ItemStack>> craftedItems = new HashMap<>();
  15.     private final HashMap<ItemStack, ItemStack> itemStacksList = new HashMap<>();
  16.  
  17.     private final RecipeCache recipeChache = ChestStorage.getInstance().getRecipeCache();
  18.     private Inventory inventory;
  19.     private Location location;
  20.     private List<ItemStack> listOfItems;
  21.     private List<ItemStack> listOfIventoryItems;
  22.     private boolean ifChestFull = false;
  23.  
  24.     public CraftingUtilitycopy(Inventory inventory, Location location, List<ItemStack> listOfItemsToCraft) {
  25.         this.inventory = inventory;
  26.         this.location = location;
  27.         this.listOfItems = listOfItemsToCraft;
  28.     }
  29.  
  30.     public HashMap<Integer, ItemStack> checkCraftingRecipeExist() {
  31.         HashMap<Integer, ItemStack> outputItemsIfNoSpaceInChest = new HashMap<>();
  32.         int itemAmont = 0;
  33.         for (Map.Entry<ItemStack, RecipeCache.RecipeData> craftingRecipe : recipeChache.getRecipe().entrySet()) {
  34.             String recipeValues = craftingRecipe.toString();
  35.             ItemStack recipeKeyitem = craftingRecipe.getKey();
  36.  
  37.             Set<ItemStack> matrialNameFirst = this.recipeChache.getRecipe(recipeKeyitem).getMatrial1();
  38.             Set<ItemStack> matrialNameSecond = this.recipeChache.getRecipe(recipeKeyitem).getMatrial2();
  39.             Set<ItemStack> matrialNameThird = this.recipeChache.getRecipe(recipeKeyitem).getMatrial3();
  40.             Set<ItemStack> matrialNameFourth = this.recipeChache.getRecipe(recipeKeyitem).getMatrial4();
  41.             Set<ItemStack> matrialNameFifth = this.recipeChache.getRecipe(recipeKeyitem).getMatrial5();
  42.  
  43.  
  44.             for (ItemStack itemListForCrafting : listOfItems) {
  45.  
  46.                 Map<Material, Integer> amountOfItemsInventory = getItemsAmount(recipeKeyitem, itemListForCrafting, this.inventory);
  47.  
  48.                 if (!amountOfItemsInventory.isEmpty()) {
  49.  
  50.                     Map<Material, ItemStack> itemStacks = setItemstacksAmount(amountOfItemsInventory, recipeKeyitem);
  51.  
  52.                     //System.out.println("recipeKeyitem " + (checkAmountForRecipeSecond(itemStacks, recipeKeyitem)));
  53.                     if (ifItAreColor(recipeKeyitem, itemListForCrafting, itemStacks) || (matrialNameFirst != null &&
  54.                             matrialNameSecond != null && matrialNameSecond.contains(ItemUtily.createItemStack()) && matrialNameThird != null && matrialNameThird.contains(ItemUtily.createItemStack()) &&
  55.                             matrialNameFourth != null && matrialNameFourth.contains(ItemUtily.createItemStack()) && matrialNameFifth != null && matrialNameFifth.contains(ItemUtily.createItemStack()))) {
  56.  
  57.                         if (/*isItemsMatch(recipeKeyitem, itemListForCrafting) &&*/
  58.                                 !itemStacks.isEmpty() && checkAmountForRecipeFirst(itemStacks, craftingRecipe.getKey(), returnItemToRecipe(matrialNameFirst, amountOfItemsInventory))) {
  59.                             Material material = returnItemToRecipe(matrialNameFirst, amountOfItemsInventory);
  60.                             Material getmatrialName = recipeKeyitem.getType();
  61.  
  62.  
  63.                             outputItemsIfNoSpaceInChest = inventory.addItem(new ItemStack(getmatrialName, checkIfItTallFlowers(material) ? recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount() + 1 : recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount()));
  64.  
  65.                             if (outputItemsIfNoSpaceInChest.isEmpty()) {
  66.                                 if (craftedItems.containsKey(this.location) && craftedItems.get(this.location).containsKey(ItemUtily.createItemStackAsOne(new ItemStack(material)))) {
  67.                                     itemAmont = craftedItems.get(this.location).get(ItemUtily.createItemStackAsOne(new ItemStack(material))).getAmount();
  68.                                     ItemStack items = craftedItems.get(this.location).get(ItemUtily.createItemStackAsOne(new ItemStack(material)));
  69.  
  70.                                     items.clone().setAmount(itemAmont);
  71.                                     this.itemStacksList.put(ItemUtily.createItemStackAsOne(new ItemStack(material)), items);
  72.  
  73.                                 }
  74.                                 this.itemStacksList.put(ItemUtily.createItemStackAsOne(new ItemStack(material)), ItemUtily.createItemStackWhitAmount(getmatrialName, (checkIfItTallFlowers(material) ? recipeChache.getRecipe().get(recipeKeyitem).getAmount1() + 1 + (craftedItems.isEmpty() ? 0 : itemAmont) : recipeChache.getRecipe().get(recipeKeyitem).getAmount1() + (craftedItems.isEmpty() ? 0 : itemAmont))));
  75.                                 craftedItems.put(this.location, this.itemStacksList);
  76.  
  77.  
  78.                                 takeItemsRecipeIngrediens(inventory, craftingRecipe.getKey(), itemStacks, material);
  79.                             }
  80.                         }
  81.  
  82.                     } else if (ifItAreColorMatchTwoItems(recipeKeyitem, itemListForCrafting, itemStacks) || (!ifItAreColor(recipeKeyitem, itemListForCrafting, itemStacks) && matrialNameFirst != null &&
  83.                             matrialNameSecond != null && matrialNameThird != null && matrialNameThird.contains(ItemUtily.createItemStack()) && matrialNameFourth != null
  84.                             && matrialNameFourth.contains(ItemUtily.createItemStack()) && matrialNameFifth != null && matrialNameFifth.contains(ItemUtily.createItemStack()))) {
  85.                         if (/*isItemsMatch(recipeKeyitem, itemListForCrafting) &&*/
  86.                                 !itemStacks.isEmpty() && checkAmountForRecipeFirst(itemStacks, recipeKeyitem, returnItemToRecipe(this.recipeChache.getRecipe(recipeKeyitem).getMatrial2(), amountOfItemsInventory)) &&
  87.                                         checkAmountForRecipeSecond(itemStacks, recipeKeyitem)) {
  88.  
  89.                             Material material = returnItemToRecipe(matrialNameFirst, amountOfItemsInventory);
  90.                             Material materialSecond = returnItemToRecipe(matrialNameSecond, amountOfItemsInventory);
  91.                             Material recipeNameOutput = recipeKeyitem.getType();
  92.  
  93.                             outputItemsIfNoSpaceInChest = inventory.addItem(ItemUtily.createItemStackWhitAmount(recipeNameOutput, isAColor(recipeNameOutput) ? (recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount() * 2) + addExtraIfSpecialcolor(materialSecond, recipeNameOutput) : recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount()));
  94.                             System.out.println("recipe " + recipeKeyitem + recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount());
  95.  
  96.                             if (outputItemsIfNoSpaceInChest.isEmpty()) {
  97.                                 if (craftedItems.containsKey(this.location) && craftedItems.get(this.location).containsKey(ItemUtily.createItemStackAsOne(new ItemStack(material)))) {
  98.                                     itemAmont = craftedItems.get(this.location).get(ItemUtily.createItemStackAsOne(new ItemStack(material))).getAmount();
  99.                                     ItemStack items = craftedItems.get(this.location).get(ItemUtily.createItemStackAsOne(new ItemStack(material)));
  100.                                     this.itemStacksList.put(ItemUtily.createItemStackAsOne(new ItemStack(material)), items);
  101.  
  102.                                 }
  103.  
  104.                                 this.itemStacksList.put(ItemUtily.createItemStackAsOne(new ItemStack(material)), ItemUtily.createItemStackWhitAmount(recipeNameOutput, isAColor(recipeNameOutput) ? ((this.recipeChache.getRecipe(recipeKeyitem).getTotalAmount() * 2) + (craftedItems.isEmpty() ? 0 : itemAmont) + addExtraIfSpecialcolor(materialSecond, recipeNameOutput)) : (this.recipeChache.getRecipe(recipeKeyitem).getTotalAmount() + (craftedItems.isEmpty() ? 0 : itemAmont))));
  105.                                 craftedItems.put(this.location, this.itemStacksList);
  106.  
  107.                                 takeItemsRecipeIngrediens(inventory, recipeKeyitem, itemStacks, materialSecond);
  108.                             }
  109.                         }
  110.                     } else if ((!ifItAreColor(recipeKeyitem, itemListForCrafting, itemStacks) && matrialNameSecond != null && matrialNameThird != null && matrialNameFourth == null && matrialNameFifth == null)) {
  111.  
  112.                         if (/*isItemsMatch(recipeKeyitem, itemListForCrafting) &&*/
  113.                                 !itemStacks.isEmpty() && checkAmountForRecipeFirst(itemStacks, recipeKeyitem, returnItemToRecipe(this.recipeChache.getRecipe(recipeKeyitem).getMatrial1(), amountOfItemsInventory)) &&
  114.                                         checkAmountForRecipeSecond(itemStacks, recipeKeyitem) && checkAmountForRecipeThird(itemStacks, craftingRecipe.getKey(), returnItemToRecipe(this.recipeChache.getRecipe(recipeKeyitem).getMatrial2(), amountOfItemsInventory))) {
  115.  
  116.                             Material material = returnItemToRecipe(matrialNameFirst, amountOfItemsInventory);
  117.                             Material materialSecond = returnItemToRecipe(matrialNameSecond, amountOfItemsInventory);
  118.                             Material matrialThird = returnItemToRecipe(this.recipeChache.getRecipe(craftingRecipe.getKey()).getMatrial3(), amountOfItemsInventory);
  119.                             Material recipeNameOutput = craftingRecipe.getKey().getType();
  120.  
  121.                             outputItemsIfNoSpaceInChest = inventory.addItem(new ItemStack(recipeNameOutput, isAColor(recipeNameOutput) ? (recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount() + 2) + addExtraIfSpecialcolor(materialSecond, recipeNameOutput) : recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount()));
  122.  
  123.  
  124.                             if (outputItemsIfNoSpaceInChest.isEmpty()) {
  125.                                 if (craftedItems.containsKey(this.location) && craftedItems.get(this.location).containsKey(ItemUtily.createItemStackAsOne(new ItemStack(material)))) {
  126.                                     itemAmont = craftedItems.get(this.location).get(ItemUtily.createItemStackAsOne(new ItemStack(material))).getAmount();
  127.                                     ItemStack items = craftedItems.get(this.location).get(ItemUtily.createItemStackAsOne(new ItemStack(material)));
  128.  
  129.                                     items.clone().setAmount(itemAmont);
  130.                                     this.itemStacksList.put(ItemUtily.createItemStackAsOne(new ItemStack(material)), items);
  131.                                 }
  132.  
  133.                                 this.itemStacksList.put(ItemUtily.createItemStackAsOne(new ItemStack(material)), ItemUtily.createItemStackWhitAmount(recipeNameOutput, isAColor(recipeNameOutput) ? (recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount() + 2) + addExtraIfSpecialcolor(materialSecond, recipeNameOutput) : (recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount() + (craftedItems.isEmpty() ? 0 : itemAmont))));
  134.                                 craftedItems.put(this.location, this.itemStacksList);
  135.  
  136.                                 takeItemsRecipeIngrediens(inventory, craftingRecipe.getKey(), itemStacks, materialSecond);
  137.                             }
  138.  
  139.                         }
  140.                     } else if ((!ifItAreColor(recipeKeyitem, itemListForCrafting, itemStacks) && matrialNameSecond != null && matrialNameThird != null && matrialNameFourth != null && matrialNameFifth == null)) {
  141.  
  142.                         if (/*isItemsMatch(recipeKeyitem, itemListForCrafting) &&*/
  143.                                 !itemStacks.isEmpty() && checkAmountForRecipeFirst(itemStacks, recipeKeyitem, returnItemToRecipe(this.recipeChache.getRecipe(craftingRecipe.getKey()).getMatrial1(), amountOfItemsInventory)) &&
  144.                                         checkAmountForRecipeSecond(itemStacks, craftingRecipe.getKey()) && checkAmountForRecipeThird(itemStacks, recipeKeyitem) &&
  145.                                         checkAmountForRecipeFourth(itemStacks, craftingRecipe.getKey())) {
  146.  
  147.                             Material material = returnItemToRecipe(matrialNameFirst, amountOfItemsInventory);
  148.                             Material materialSecond = returnItemToRecipe(matrialNameSecond, amountOfItemsInventory);
  149.                             Material recipeNameOutput = Material.valueOf(Crafting.valueOf(recipeValues).name());
  150.  
  151.                             outputItemsIfNoSpaceInChest = inventory.addItem(new ItemStack(recipeNameOutput, isAColor(recipeNameOutput) ? (recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount() + 2) + addExtraIfSpecialcolor(materialSecond, recipeNameOutput) : recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount()));
  152.  
  153.  
  154.                             if (outputItemsIfNoSpaceInChest.isEmpty()) {
  155.                                 if (craftedItems.containsKey(this.location) && craftedItems.get(this.location).containsKey(ItemUtily.createItemStackAsOne(new ItemStack(material)))) {
  156.                                     itemAmont = craftedItems.get(this.location).get(ItemUtily.createItemStackAsOne(new ItemStack(material))).getAmount();
  157.                                     ItemStack items = craftedItems.get(this.location).get(ItemUtily.createItemStackAsOne(new ItemStack(material)));
  158.  
  159.                                     items.clone().setAmount(itemAmont);
  160.                                     this.itemStacksList.put(ItemUtily.createItemStackAsOne(new ItemStack(material)), items);
  161.                                 }
  162.  
  163.                                 this.itemStacksList.put(ItemUtily.createItemStackAsOne(new ItemStack(material)), ItemUtily.createItemStackWhitAmount(recipeNameOutput, isAColor(recipeNameOutput) ? (recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount() + 2) + addExtraIfSpecialcolor(materialSecond, recipeNameOutput) : (recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount() + (craftedItems.isEmpty() ? 0 : itemAmont))));
  164.                                 craftedItems.put(this.location, this.itemStacksList);
  165.  
  166.                                 takeItemsRecipeIngrediens(inventory, craftingRecipe.getKey(), itemStacks, null);
  167.                             }
  168.  
  169.                         }
  170.                     } else if ((!ifItAreColor(recipeKeyitem, itemListForCrafting, itemStacks) && matrialNameSecond != null && matrialNameThird != null && matrialNameFourth != null && matrialNameFifth != null)) {
  171.  
  172.                         if (/*isItemsMatch(recipeKeyitem, itemListForCrafting) &&*/
  173.                                 !itemStacks.isEmpty() && checkAmountForRecipeFirst(itemStacks, craftingRecipe.getKey(), returnItemToRecipe(this.recipeChache.getRecipe(craftingRecipe.getKey()).getMatrial1(), amountOfItemsInventory)) &&
  174.                                         checkAmountForRecipeSecond(itemStacks, recipeKeyitem) && checkAmountForRecipeThird(itemStacks, recipeKeyitem) &&
  175.                                         checkAmountForRecipeFourth(itemStacks, recipeKeyitem) && checkAmountForRecipeFifth(itemStacks, recipeKeyitem)) {
  176.  
  177.                             Material material = returnItemToRecipe(matrialNameFirst, amountOfItemsInventory);
  178.                             Material materialSecond = returnItemToRecipe(matrialNameSecond, amountOfItemsInventory);
  179.                             Material recipeNameOutput = Material.valueOf(Crafting.valueOf(recipeValues).name());
  180.  
  181.  
  182.                             outputItemsIfNoSpaceInChest = inventory.addItem(new ItemStack(recipeNameOutput, isAColor(recipeNameOutput) ? (recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount() + 2) + addExtraIfSpecialcolor(materialSecond, recipeNameOutput) : recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount()));
  183.  
  184.  
  185.                             if (outputItemsIfNoSpaceInChest.isEmpty()) {
  186.                                 if (craftedItems.containsKey(this.location) && craftedItems.get(this.location).containsKey(ItemUtily.createItemStackAsOne(new ItemStack(material)))) {
  187.                                     itemAmont = craftedItems.get(this.location).get(ItemUtily.createItemStackAsOne(new ItemStack(material))).getAmount();
  188.                                     ItemStack items = craftedItems.get(this.location).get(ItemUtily.createItemStackAsOne(new ItemStack(material)));
  189.  
  190.                                     items.clone().setAmount(itemAmont);
  191.                                     this.itemStacksList.put(ItemUtily.createItemStackAsOne(new ItemStack(material)), items);
  192.                                 }
  193.  
  194.                                 this.itemStacksList.put(ItemUtily.createItemStackAsOne(new ItemStack(material)), ItemUtily.createItemStackWhitAmount(recipeNameOutput, isAColor(recipeNameOutput) ? (recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount() + 2) + addExtraIfSpecialcolor(materialSecond, recipeNameOutput) : (recipeChache.getRecipe().get(recipeKeyitem).getTotalAmount() + (craftedItems.isEmpty() ? 0 : itemAmont))));
  195.                                 craftedItems.put(this.location, this.itemStacksList);
  196.  
  197.                                 takeItemsRecipeIngrediens(inventory, recipeKeyitem, itemStacks, null);
  198.                             }
  199.                         }
  200.                     }
  201.                 }
  202.             }
  203.  
  204.         }
  205.         return outputItemsIfNoSpaceInChest;
  206.     }
  207.  
  208.  
  209.     /**
  210.      * Check if it a color recipe, is for bypass the check if the recipe has more an one matral to use and the
  211.      * items you has added only demand 1 for the recipe, it will dynamicly chose right type after amount items
  212.      * for the recipe.
  213.      * <p>
  214.      * So for example light_gray_dye has two diffrent type of recipe one ony need one item and second need two diffrent item.
  215.      * It will shose that type some fith the cuurent added items.
  216.      *
  217.      * @param craftingRecipe      the recipe you whant to check aginst.
  218.      * @param itemListForCrafting the list of items you want to craft too.
  219.      * @param inventoryItems      the items inside the inventory
  220.      * @return if the item inside the inventory match the items inside the recipe
  221.      */
  222.  
  223.     public boolean ifItAreColor(ItemStack craftingRecipe, ItemStack itemListForCrafting, Map<Material, ItemStack> inventoryItems) {
  224.  
  225.         if (craftingRecipe.isSimilar(ItemUtily.createItemStackAsOne(Material.LIGHT_BLUE_DYE)) && itemListForCrafting.isSimilar(ItemUtily.createItemStackAsOne(Material.LIGHT_BLUE_DYE)))
  226.             for (ItemStack recipe : recipeChache.getRecipe().get(craftingRecipe).getMatrial1()) {
  227.                 for (ItemStack items : inventoryItems.values()) {
  228.  
  229.                     if (items.isSimilar(ItemUtily.createItemStackAsOne(Material.BLUE_ORCHID)))
  230.                         if (recipe.isSimilar(items)) {
  231.                             return true;
  232.                         }
  233.                 }
  234.             }
  235.         else if (craftingRecipe.isSimilar(ItemUtily.createItemStackAsOne(Material.LIGHT_GRAY_DYE)) && itemListForCrafting.isSimilar(ItemUtily.createItemStackAsOne(Material.LIGHT_GRAY_DYE)))
  236.             for (ItemStack recipe : recipeChache.getRecipe().get(craftingRecipe).getMatrial1()) {
  237.                 for (ItemStack items : inventoryItems.values()) {
  238.  
  239.                     if (items.isSimilar(ItemUtily.createItemStackAsOne(Material.WHITE_TULIP)) || items.isSimilar(ItemUtily.createItemStackAsOne(Material.OXEYE_DAISY)) || items.isSimilar(ItemUtily.createItemStackAsOne(Material.AZURE_BLUET)))
  240.                         if (recipe.isSimilar(items)) {
  241.                             return true;
  242.                         }
  243.                 }
  244.             }
  245.         else if (craftingRecipe.isSimilar(ItemUtily.createItemStackAsOne(Material.MAGENTA_DYE)) && itemListForCrafting.isSimilar(ItemUtily.createItemStackAsOne(Material.MAGENTA_DYE)))
  246.             for (ItemStack recipe : recipeChache.getRecipe().get(craftingRecipe).getMatrial1()) {
  247.                 for (ItemStack items : inventoryItems.values()) {
  248.  
  249.                     if (items.isSimilar(ItemUtily.createItemStackAsOne(Material.ALLIUM)) || items.isSimilar(ItemUtily.createItemStackAsOne(Material.LILAC)))
  250.                         if (recipe.isSimilar(items)) {
  251.                             return true;
  252.                         }
  253.                 }
  254.             }
  255.         else if (craftingRecipe.isSimilar(ItemUtily.createItemStackAsOne(Material.PINK_DYE)) && itemListForCrafting.isSimilar(ItemUtily.createItemStackAsOne(Material.PINK_DYE)))
  256.             for (ItemStack recipe : recipeChache.getRecipe().get(craftingRecipe).getMatrial1()) {
  257.                 for (ItemStack items : inventoryItems.values()) {
  258.  
  259.                     if (items.isSimilar(ItemUtily.createItemStackAsOne(Material.PINK_TULIP)) || items.isSimilar(ItemUtily.createItemStackAsOne(Material.PEONY)))
  260.                         if (recipe.isSimilar(items)) {
  261.                             return true;
  262.                         }
  263.                 }
  264.             }
  265.         else if (craftingRecipe.isSimilar(ItemUtily.createItemStackAsOne(Material.RED_DYE)) && itemListForCrafting.isSimilar(ItemUtily.createItemStackAsOne(Material.RED_DYE)))
  266.             for (ItemStack recipe : recipeChache.getRecipe().get(craftingRecipe).getMatrial1()) {
  267.                 for (ItemStack items : inventoryItems.values()) {
  268.  
  269.                     if (items.isSimilar(ItemUtily.createItemStackAsOne(Material.RED_TULIP)) || items.isSimilar(ItemUtily.createItemStackAsOne(Material.BEETROOT)) || items.isSimilar(ItemUtily.createItemStackAsOne(Material.POPPY)) || items.isSimilar(ItemUtily.createItemStackAsOne(Material.ROSE_BUSH)))
  270.                         if (recipe.isSimilar(items)) {
  271.                             System.out.println("items " + items);
  272.                             return true;
  273.                         }
  274.                 }
  275.             }
  276.  
  277.  
  278.         return false;
  279.     }
  280.  
  281.     /**
  282.      * Check if it a tall flower
  283.      *
  284.      * @param itemUsecrafting the item you added inside the inventory to check
  285.      * @return true if the item are a tall flower.
  286.      */
  287.     public boolean checkIfItTallFlowers(Material itemUsecrafting) {
  288.         if (itemUsecrafting != null)
  289.             return itemUsecrafting == Material.LILAC || itemUsecrafting == Material.PEONY || itemUsecrafting == Material.ROSE_BUSH;
  290.         return false;
  291.     }
  292.  
  293.     /**
  294.      * check if colors match if the recipe has more an 2 diffrent recipe ingredens and bypass the check.
  295.      * Is for recipe some has 1,2 and 3 diffreent items, but only added 2 matched items inside the inventory.
  296.      *
  297.      * @param craftingRecipe      the recipe you want to check against
  298.      * @param itemListForCrafting the list of items you has added you want to craft.
  299.      * @param inventoryItems      the contents of the inventory
  300.      * @return true if the items match the recipe demand.
  301.      */
  302.     public boolean ifItAreColorMatchTwoItems(ItemStack craftingRecipe, ItemStack itemListForCrafting, Map<Material, ItemStack> inventoryItems) {
  303.  
  304.         if (craftingRecipe.isSimilar(ItemUtily.createItemStackAsOne(Material.MAGENTA_DYE)) && itemListForCrafting.isSimilar(ItemUtily.createItemStackAsOne(Material.MAGENTA_DYE)))
  305.             for (ItemStack recipe : this.recipeChache.getRecipe().get(craftingRecipe).getMatrial1()) {
  306.                 for (ItemStack items : inventoryItems.values()) {
  307.  
  308.                     if (items.isSimilar(ItemUtily.createItemStackAsOne(Material.PINK_DYE)) || items.isSimilar(ItemUtily.createItemStackAsOne(Material.PURPLE_DYE)))
  309.                         if (recipe.isSimilar(items)) {
  310.                             System.out.println("items are " + items);
  311.                             return true;
  312.                         }
  313.                 }
  314.             }
  315.  
  316.         return false;
  317.     }
  318.  
  319.     /**
  320.      * Simpel check if it a color.
  321.      *
  322.      * @param outputItem the item you want to make.
  323.      * @return true if it a color recipe.
  324.      */
  325.     public boolean isAColor(Material outputItem) {
  326.         switch (outputItem) {
  327.             case BLACK_DYE:
  328.             case CYAN_DYE:
  329.             case LIGHT_BLUE_DYE:
  330.             case LIGHT_GRAY_DYE:
  331.             case MAGENTA_DYE:
  332.             case ORANGE_DYE:
  333.             case PINK_DYE:
  334.             case RED_DYE:
  335.                 return true;
  336.             default:
  337.                 return false;
  338.         }
  339.     }
  340.  
  341.     /**
  342.      * Check if it a color and add extra item if it is a special color some has more items as output.
  343.      *
  344.      * @param itemToTake the item you has added to the inventory
  345.      * @param outputItem the recipe output.
  346.      * @return a number if it a match or 0 if not.
  347.      */
  348.  
  349.  
  350.     public int addExtraIfSpecialcolor(Material itemToTake, Material outputItem) {
  351.         switch (outputItem) {
  352.             case LIGHT_GRAY_DYE:
  353.                 if (itemToTake == Material.BLACK_DYE)
  354.                     return 1;
  355.             case BLACK_DYE:
  356.             case CYAN_DYE:
  357.             case LIGHT_BLUE_DYE:
  358.             case MAGENTA_DYE:
  359.                 if (itemToTake == Material.WHITE_DYE)
  360.                     return 1;
  361.             case ORANGE_DYE:
  362.             case PINK_DYE:
  363.             case RED_DYE:
  364.             default:
  365.                 return 0;
  366.         }
  367.     }
  368.  
  369.     public boolean checkIfChestFull() {
  370.  
  371.         if (checkCraftingRecipeExist().isEmpty()) {
  372.             ifChestFull = !checkCraftingRecipeExist().isEmpty();
  373.         }
  374.  
  375.         return ifChestFull;
  376.     }
  377.  
  378.     /**
  379.      * Will set amount of items inside the inventory after the matched recipe ingredens.
  380.      *
  381.      * @param ingrediensMap the items inside the inventory.
  382.      * @param recipes       the ingrediens you need to make the recipe.
  383.      * @return a map with the items and the amount is set inside the stack
  384.      */
  385.     public Map<Material, ItemStack> setItemstacksAmount(Map<Material, Integer> ingrediensMap, ItemStack recipes) {
  386.         Map<Material, ItemStack> map = new HashMap<>();
  387.  
  388.         ItemStack recipeMatrial;
  389.         ItemStack recipeMatrialSecond;
  390.         ItemStack recipeMatrialThird;
  391.         ItemStack recipeMatrialFourth;
  392.         ItemStack recipeMatrialFifth;
  393.  
  394.         if (returnItemToRecipe(this.recipeChache.getRecipe(recipes).getMatrial1(), ingrediensMap) != null)
  395.             if (this.recipeChache.getRecipe(recipes).getMatrial1() != null && isMapContainsRecipeIngrediens(this.recipeChache.getRecipe(recipes).getMatrial1(), ingrediensMap)) {
  396.                 for (Map.Entry<Material, Integer> item : ingrediensMap.entrySet())
  397.                     if (isMatrial1Match(recipes, ItemUtily.createItemStack(item.getKey()))) {
  398.                         Material matrialNameFirst = item.getKey();
  399.                         int itemAmountSecond = ingrediensMap.get(matrialNameFirst);
  400.                         recipeMatrial = new ItemStack(matrialNameFirst, itemAmountSecond);
  401.                         map.put(matrialNameFirst, recipeMatrial);
  402.                     }
  403.             }
  404.         if (returnItemToRecipe(this.recipeChache.getRecipe(recipes).getMatrial2(), ingrediensMap) != null)
  405.             if (this.recipeChache.getRecipe(recipes).getMatrial2() != null && isMapContainsRecipeIngrediens(this.recipeChache.getRecipe(recipes).getMatrial2(), ingrediensMap)) {
  406.                 for (Map.Entry<Material, Integer> item : ingrediensMap.entrySet())
  407.                     if (isMatrial2Match(recipes, ItemUtily.createItemStack(item.getKey()))) {
  408.                         Material matrialNameSecond = item.getKey();
  409.                         int itemAmountSecond = ingrediensMap.get(matrialNameSecond);
  410.                         recipeMatrialSecond = new ItemStack(matrialNameSecond, itemAmountSecond);
  411.                         map.put(matrialNameSecond, recipeMatrialSecond);
  412.  
  413.                     }
  414.  
  415.             }
  416.         if (returnItemToRecipe(this.recipeChache.getRecipe(recipes).getMatrial3(), ingrediensMap) != null)
  417.             if (this.recipeChache.getRecipe(recipes).getMatrial3() != null && isMapContainsRecipeIngrediens(this.recipeChache.getRecipe(recipes).getMatrial3(), ingrediensMap)) {
  418.                 Material matrialNameThird = returnItemToRecipe(this.recipeChache.getRecipe(recipes).getMatrial3(), ingrediensMap);
  419.                 int itemAmountThird = ingrediensMap.get(matrialNameThird);
  420.                 recipeMatrialThird = new ItemStack(matrialNameThird, itemAmountThird);
  421.                 map.put(matrialNameThird, recipeMatrialThird);
  422.             }
  423.         if (returnItemToRecipe(this.recipeChache.getRecipe(recipes).getMatrial4(), ingrediensMap) != null)
  424.             if (this.recipeChache.getRecipe(recipes).getMatrial4() != null && isMapContainsRecipeIngrediens(this.recipeChache.getRecipe(recipes).getMatrial4(), ingrediensMap)) {
  425.                 Material matrialNameFourth = returnItemToRecipe(this.recipeChache.getRecipe(recipes).getMatrial4(), ingrediensMap);
  426.                 int itemAmountFourth = ingrediensMap.get(matrialNameFourth);
  427.                 recipeMatrialFourth = new ItemStack(matrialNameFourth, itemAmountFourth);
  428.                 map.put(matrialNameFourth, recipeMatrialFourth);
  429.             }
  430.         if (returnItemToRecipe(this.recipeChache.getRecipe(recipes).getMatrial5(), ingrediensMap) != null)
  431.             if (this.recipeChache.getRecipe(recipes).getMatrial5() != null && isMapContainsRecipeIngrediens(this.recipeChache.getRecipe(recipes).getMatrial5(), ingrediensMap)) {
  432.                 Material matrialNameFifth = returnItemToRecipe(this.recipeChache.getRecipe(recipes).getMatrial5(), ingrediensMap);
  433.                 int itemAmountFifth = ingrediensMap.get(matrialNameFifth);
  434.                 recipeMatrialFifth = new ItemStack(matrialNameFifth, itemAmountFifth);
  435.                 map.put(matrialNameFifth, recipeMatrialFifth);
  436.             }
  437.  
  438.         return map;
  439.     }
  440.  
  441.     /**
  442.      * Count items inside the inventory, some match the recipe ingredens.
  443.      * It will compere the recipe you want to makw with the list of recipe
  444.      * some exist in Crafting.
  445.      *
  446.      * @param recipes            you want to match against.
  447.      * @param theRecipeYouWhants the recipe you want to match.
  448.      * @param inventory          the inventory you match the items from.
  449.      * @return a map with the Matrial and amount of this type inside the inventory.
  450.      */
  451.  
  452.     public Map<Material, Integer> getItemsAmount(ItemStack recipes, ItemStack theRecipeYouWhants, Inventory inventory) {
  453.         Map<Material, Integer> map = new HashMap<>();
  454.         ItemStack[] itemStacks = inventory.getContents();
  455.         int amountFirst = 0;
  456.         int amountSecond = 0;
  457.         int amountThird = 0;
  458.         int amountFourt = 0;
  459.         int amountFifth = 0;
  460.  
  461.  
  462.         for (ItemStack itemStack : itemStacks) {
  463.  
  464.             //System.out.println(" ingrediens  " + itemStack + theRecipeYouWhants.isSimilar(recipes));
  465.             if (theRecipeYouWhants.isSimilar(recipes) && itemStack != null) {
  466.                 if (isMatrial1Match(recipes, itemStack)) {
  467.                     amountFirst += itemStack.getAmount();
  468.                     map.put(itemStack.getType(), ItemUtily.countItemStacks(itemStacks, itemStack));
  469.                 } else if (isMatrial2Match(recipes, itemStack)) {
  470.                     amountSecond += itemStack.getAmount();
  471.                     map.put(itemStack.getType(), ItemUtily.countItemStacks(itemStacks, itemStack));
  472.                 } else if (isMatrial3Match(recipes, itemStack)) {
  473.                     amountThird += itemStack.getAmount();
  474.                     map.put(itemStack.getType(), ItemUtily.countItemStacks(itemStacks, itemStack));
  475.                 } else if (isMatrial4Match(recipes, itemStack)) {
  476.                     amountFourt += itemStack.getAmount();
  477.                     map.put(itemStack.getType(), ItemUtily.countItemStacks(itemStacks, itemStack));
  478.                 } else if (isMatrial5Match(recipes, itemStack)) {
  479.                     amountFifth += itemStack.getAmount();
  480.                     map.put(itemStack.getType(), ItemUtily.countItemStacks(itemStacks, itemStack));
  481.                 }
  482.             }
  483.         }
  484.  
  485.         return map;
  486.     }
  487.  
  488.     /**
  489.      * Remove the items inside the inventory if it exist inbside the inventory
  490.      *
  491.      * @param inventory the inventory the items shall be removed from.
  492.      * @param itemStack the item you want to remove.
  493.      */
  494.  
  495.     public void removeItems(Inventory inventory, ItemStack itemStack) {
  496.  
  497.         for (int i = 0; i < inventory.getSize(); i++) {
  498.             ItemStack itemStacks = inventory.getContents()[i];
  499.             if (itemStacks != null && itemStacks.isSimilar(itemStack)) {
  500.                 inventory.setItem(i, new ItemStack(Material.AIR));
  501.             }
  502.         }
  503.     }
  504.  
  505.     /**
  506.      * Check to remove right item from the inventory and amount it shall be removed.
  507.      * It will add new amount inside the inventory.
  508.      *
  509.      * @param inventory  some you remove and add items too.
  510.      * @param recipes    the craftingrecipes it vill check items to remove against.
  511.      * @param itemStacks the itemstacks some the inventory contains and amount.
  512.      * @param itemToTake the item you want to check from the inventory match some conditons
  513.      *                   (in this case if it a color, soo it to remove right amount).
  514.      */
  515.     public void takeItemsRecipeIngrediens(Inventory inventory, ItemStack recipes, Map<Material, ItemStack> itemStacks, Material itemToTake) {
  516.         Set<ItemStack> ifItHasRemovedSameItem = new HashSet<>();
  517.         for (Map.Entry<Material, ItemStack> item : itemStacks.entrySet()) {
  518.             ItemStack itemStack = item.getValue();
  519.  
  520.             if (itemStack != null && isMatrial1Match(recipes, itemStack)) {
  521.                 if (itemStack.getAmount() >= this.recipeChache.getRecipe(recipes).getAmount1() && !ifItHasRemovedSameItem.isEmpty()) {
  522.                     if (ifItHasRemovedSameItem.size() == ItemUtily.countItemStacks(inventory, itemStack))
  523.                         ifItHasRemovedSameItem.clear();
  524.                     ifItHasRemovedSameItem.add(itemStack);
  525.                     continue;
  526.                 }
  527.                 removeItems(inventory, itemStack);
  528.                 itemStack.setAmount(checkAdvanceColorRecipes(recipes, itemToTake) ? itemStack.getAmount() - (this.recipeChache.getRecipe(recipes).getAmount1() + 1) : itemStack.getAmount() - this.recipeChache.getRecipe(recipes).getAmount1());
  529.                 inventory.addItem(itemStack);
  530.                 ifItHasRemovedSameItem.add(itemStack);
  531.             } else if (itemStack != null && isMatrial2Match(recipes, itemStack)) {
  532.                 if (checkAdvanceColorRecipes(recipes, itemToTake) && itemStack.getType() == Material.PINK_DYE)
  533.                     continue;
  534.                 if (!checkAdvanceColorRecipes(recipes, itemToTake) && itemStack.getType() == Material.WHITE_DYE)
  535.                     continue;
  536.                 removeItems(inventory, itemStack);
  537.                 itemStack.setAmount(itemStack.getAmount() - this.recipeChache.getRecipe(recipes).getAmount2());
  538.                 inventory.addItem(itemStack);
  539.  
  540.             } else if (itemStack != null && isMatrial3Match(recipes, itemStack)) {
  541.                 removeItems(inventory, itemStack);
  542.                 itemStack.setAmount(checkAdvanceColorRecipes(recipes, itemToTake) ? itemStack.getAmount() - (this.recipeChache.getRecipe(recipes).getAmount3() + 1) : itemStack.getAmount() - this.recipeChache.getRecipe(recipes).getAmount3());
  543.                 inventory.addItem(itemStack);
  544.  
  545.             } else if (itemStack != null && isMatrial4Match(recipes, itemStack)) {
  546.                 removeItems(inventory, itemStack);
  547.                 itemStack.setAmount(itemStack.getAmount() - this.recipeChache.getRecipe(recipes).getAmount4());
  548.                 inventory.addItem(itemStack);
  549.  
  550.             } else if (itemStack != null && isMatrial5Match(recipes, itemStack)) {
  551.                 removeItems(inventory, itemStack);
  552.                 itemStack.setAmount(itemStack.getAmount() - this.recipeChache.getRecipe(recipes).getAmount5());
  553.                 inventory.addItem(itemStack);
  554.  
  555.             }
  556.         }
  557.     }
  558.  
  559.     /**
  560.      * check if it a special color and return true if it is.
  561.      *
  562.      * @param recipeOutput     the recipe it curently try to make
  563.      * @param itemUsedInrecipe the item you want to check if the recipe contains the item.
  564.      * @return true if it match a special color.
  565.      */
  566.     private boolean checkAdvanceColorRecipes(ItemStack recipeOutput, Material itemUsedInrecipe) {
  567.         if (itemUsedInrecipe != null)
  568.             if (recipeOutput.getType() == Material.LIGHT_GRAY_DYE && itemUsedInrecipe == Material.LIGHT_GRAY_DYE)
  569.                 return true;
  570.             else if (recipeOutput.getType() == Material.MAGENTA_DYE && (itemUsedInrecipe == Material.WHITE_DYE || itemUsedInrecipe == Material.BONE_MEAL))
  571.                 return true;
  572.  
  573.         return false;
  574.     }
  575.  
  576.     /**
  577.      * Check if a item match the item demanded for the recipe.
  578.      *
  579.      * @param recipes      from the recipe
  580.      * @param itemYoucraft the items you want to check if it match the curent recipe
  581.      * @return true if the items match the curent recipe.
  582.      */
  583.  
  584.     public boolean isMatrial1Match(ItemStack recipes, ItemStack itemYoucraft) {
  585.  
  586.  
  587.         if (recipes != null && itemYoucraft != null) {
  588.             for (ItemStack recipe : this.recipeChache.getRecipe(recipes).getMatrial1())
  589.                 if (recipe.isSimilar(itemYoucraft)) {
  590.                     return true;
  591.                 }
  592.         }
  593.         return false;
  594.     }
  595.  
  596.     /**
  597.      * Check if a item match the item demanded for the recipe.
  598.      *
  599.      * @param recipes      from the recipe
  600.      * @param itemYoucraft the items you want to check if it match the curent recipe
  601.      * @return true if the items match the curent recipe.
  602.      */
  603.  
  604.     public boolean isMatrial2Match(ItemStack recipes, ItemStack itemYoucraft) {
  605.  
  606.  
  607.         if (recipes != null && itemYoucraft != null) {
  608.             for (ItemStack recipess : this.recipeChache.getRecipe(recipes).getMatrial2())
  609.                 if (recipess.isSimilar(itemYoucraft)) {
  610.                     return true;
  611.                 }
  612.         }
  613.         return false;
  614.     }
  615.  
  616.     /**
  617.      * Check if a item match the item demanded for the recipe.
  618.      *
  619.      * @param recipes      from the recipe
  620.      * @param itemYoucraft the items you want to check if it match the curent recipe
  621.      * @return true if the items match the curent recipe.
  622.      */
  623.  
  624.     public boolean isMatrial3Match(ItemStack recipes, ItemStack itemYoucraft) {
  625.  
  626.  
  627.         if (recipes != null && itemYoucraft != null) {
  628.  
  629.             for (ItemStack recipesss : this.recipeChache.getRecipe(recipes).getMatrial3())
  630.                 if (recipesss.isSimilar(itemYoucraft)) {
  631.                     return true;
  632.                 }
  633.  
  634.         }
  635.         return false;
  636.     }
  637.  
  638.     /**
  639.      * Check if a item match the item demanded for the recipe.
  640.      *
  641.      * @param recipes      from the recipe
  642.      * @param itemYoucraft the items you want to check if it match the curent recipe
  643.      * @return true if the items match the curent recipe.
  644.      */
  645.  
  646.     public boolean isMatrial4Match(ItemStack recipes, ItemStack itemYoucraft) {
  647.  
  648.  
  649.         if (recipes != null && itemYoucraft != null) {
  650.  
  651.             for (ItemStack recipessss : this.recipeChache.getRecipe(recipes).getMatrial4())
  652.                 if (recipessss.isSimilar(itemYoucraft)) {
  653.                     return true;
  654.                 }
  655.  
  656.  
  657.         }
  658.         return false;
  659.     }
  660.  
  661.     /**
  662.      * Check if a item match the item demanded for the recipe.
  663.      *
  664.      * @param recipes      from the recipe
  665.      * @param itemYoucraft the items you want to check if it match the curent recipe
  666.      * @return true if the items match the curent recipe.
  667.      */
  668.  
  669.     public boolean isMatrial5Match(ItemStack recipes, ItemStack itemYoucraft) {
  670.  
  671.  
  672.         if (recipes != null && itemYoucraft != null) {
  673.             for (ItemStack recipesssss : this.recipeChache.getRecipe(recipes).getMatrial5())
  674.                 if (recipesssss.isSimilar(itemYoucraft)) {
  675.                     return true;
  676.                 }
  677.  
  678.         }
  679.         return false;
  680.     }
  681.  
  682.     /**
  683.      * Check recipe ingrediens to the items inside the inventory.
  684.      *
  685.      * @param ingrediens the recipe ingridens.
  686.      * @param map        the contents of your inventory.
  687.      * @return a item if it match or null if it not find any match.
  688.      */
  689.  
  690.     public Material returnItemToRecipe(Set<ItemStack> ingrediens, Map<Material, Integer> map) {
  691.  
  692.         for (Map.Entry<Material, Integer> itemStack : map.entrySet())
  693.             if (ingrediens != null && itemStack != null)
  694.                 for (ItemStack recipe : ingrediens) {
  695.  
  696.                     if (recipe.getType() == itemStack.getKey()) {
  697.                         return itemStack.getKey();
  698.                     }
  699.  
  700.                 }
  701.         return null;
  702.     }
  703.  
  704.     /**
  705.      * Check if the map contains the needed recipe ingrediens.
  706.      *
  707.      * @param ingrediens the curent recipe ingredins to check.
  708.      * @param map        the inventory contents
  709.      * @return true if the item match recipe ingredien.
  710.      */
  711.     public boolean isMapContainsRecipeIngrediens(Set<ItemStack> ingrediens, Map<Material, Integer> map) {
  712.  
  713.         for (Map.Entry<Material, Integer> itemStack : map.entrySet())
  714.             if (ingrediens != null && itemStack != null)
  715.                 for (ItemStack recipe : ingrediens) {
  716.  
  717.                     if (recipe.getType() == itemStack.getKey()) {
  718.                         return true;
  719.                     }
  720.  
  721.                 }
  722.  
  723.         return false;
  724.     }
  725.  
  726.     /**
  727.      * Some recipe has several diffrent items you can choose from, this will split up the recipe ingrediens
  728.      * and check every one aginst the item inside the inventory and return a item if it match.
  729.      *
  730.      * @param itemFromInventory    the item inside the inventory
  731.      * @param ingrediensFromRecipe the recipe ingridens some it deamand
  732.      * @return the matching item if it exist or return null if it not a match.
  733.      */
  734.  
  735.     public Material splitIngrediens(Material itemFromInventory, Set<ItemStack> ingrediensFromRecipe) {
  736.  
  737.         if (itemFromInventory != null && ingrediensFromRecipe != null)
  738.             for (ItemStack ingredien : ingrediensFromRecipe)
  739.                 if (ingredien.getType() == itemFromInventory) {
  740.                     return itemFromInventory;
  741.                 }
  742.         return null;
  743.     }
  744.  
  745.     /**
  746.      * Check the amount of item one type or if recipe has several diffrent matrial it can use
  747.      * it include even this from the inventory.
  748.      * <p>
  749.      * Like for example planks has several wood types, but you can use several diffrent type´s to craft
  750.      * an item.
  751.      *
  752.      * @param itemsInsideInventory the items you have inside the inventory
  753.      * @param craftingRecipes      the recipe ingridient you want to match aginst.
  754.      * @param itemUsedToCrafting   the item some you want to check (in this case I use it for colors some has diffrent recipe)
  755.      * @return true if it equal or more items inside the inventory.
  756.      */
  757.  
  758.     public boolean checkAmountForRecipeFirst(Map<Material, ItemStack> itemsInsideInventory, ItemStack craftingRecipes, Material... itemUsedToCrafting) {
  759.         int itemAmount = 0;
  760.         boolean matchedItem = false;
  761.         if (itemUsedToCrafting != null)
  762.             for (Material items : itemUsedToCrafting)
  763.                 if (items == Material.BLACK_DYE) {
  764.                     matchedItem = true;
  765.                     break;
  766.                 }
  767.  
  768.         if (itemsInsideInventory != null && craftingRecipes != null)
  769.             for (Map.Entry<Material, ItemStack> item : itemsInsideInventory.entrySet()) {
  770.                 if (item.getValue().getType() == splitIngrediens(item.getValue().getType(), this.recipeChache.getRecipe().get(craftingRecipes).getMatrial1())) {
  771.                     itemAmount += item.getValue().getAmount();
  772.                     if (itemAmount >= ((craftingRecipes.isSimilar(ItemUtily.createItemStackAsOne(Material.LIGHT_GRAY_DYE)) && matchedItem) ?
  773.                             this.recipeChache.getRecipe().get(craftingRecipes).getAmount1() + 1 : this.recipeChache.getRecipe().get(craftingRecipes).getAmount1())) {
  774.                         return true;
  775.                     }
  776.                 }
  777.             }
  778.         return false;
  779.     }
  780.  
  781.     /**
  782.      * Check the amount of item one type or if recipe has several diffrent matrial it can use
  783.      * it include even this from the inventory.
  784.      * <p>
  785.      * Like for example planks has several wood types, but you can use several diffrent type´s to craft
  786.      * an item.
  787.      *
  788.      * @param itemsInsideInventory the items you have inside the inventory
  789.      * @param craftingRecipes      the recipe ingridient you want to match aginst.
  790.      * @param itemUsedToCrafting   the item some you want to check (in this case I use it for colors some has diffrent recipe)
  791.      * @return true if it equal or more items inside the inventory.
  792.      */
  793.     public boolean checkAmountForRecipeSecond(Map<Material, ItemStack> itemsInsideInventory, ItemStack craftingRecipes, Material... itemUsedToCrafting) {
  794.         int itemSecondAmount = 0;
  795.         boolean matchedItem = false;
  796.         if (itemUsedToCrafting != null)
  797.             for (Material items : itemUsedToCrafting)
  798.                 if (items == Material.MAGENTA_DYE) {
  799.                     matchedItem = true;
  800.                     break;
  801.                 }
  802.  
  803.         if (itemsInsideInventory != null && craftingRecipes != null)
  804.             for (Map.Entry<Material, ItemStack> item : itemsInsideInventory.entrySet()) {
  805.  
  806.                 if (item.getValue().getType() == splitIngrediens(item.getValue().getType(), this.recipeChache.getRecipe().get(craftingRecipes).getMatrial2())) {
  807.                     itemSecondAmount += item.getValue().getAmount();
  808.                     if (itemSecondAmount >= this.recipeChache.getRecipe().get(craftingRecipes).getAmount2())
  809.                         return true;
  810.  
  811.                 }
  812.  
  813.             }
  814.  
  815.         return false;
  816.     }
  817.  
  818.     /**
  819.      * Check the amount of item one type or if recipe has several diffrent matrial it can use
  820.      * it include even this from the inventory.
  821.      * <p>
  822.      * Like for example planks has several wood types, but you can use several diffrent type´s to craft
  823.      * an item.
  824.      *
  825.      * @param itemsInsideInventory the items you have inside the inventory
  826.      * @param craftingRecipes      the recipe ingridient you want to match aginst.
  827.      * @param itemUsedToCrafting   the item some you want to check (in this case I use it fot colors some has diffrent recipe)
  828.      * @return true if it equal or more items inside the inventory.
  829.      */
  830.     public boolean checkAmountForRecipeThird(Map<Material, ItemStack> itemsInsideInventory, ItemStack craftingRecipes, Material... itemUsedToCrafting) {
  831.         int itemAmount = 0;
  832.  
  833.         boolean matchedItem = false;
  834.         if (itemUsedToCrafting != null)
  835.             for (Material items : itemUsedToCrafting)
  836.                 if (items == Material.WHITE_DYE || items == Material.BONE_MEAL) {
  837.                     matchedItem = true;
  838.                     break;
  839.                 }
  840.  
  841.         if (itemsInsideInventory != null && craftingRecipes != null)
  842.             for (Map.Entry<Material, ItemStack> item : itemsInsideInventory.entrySet()) {
  843.                 if (item.getValue().getType() == splitIngrediens(item.getValue().getType(), this.recipeChache.getRecipe().get(craftingRecipes).getMatrial3())) {
  844.                     itemAmount += item.getValue().getAmount();
  845.                     if (itemAmount >= ((craftingRecipes.isSimilar(ItemUtily.createItemStackAsOne(Material.MAGENTA_DYE)) && matchedItem) ?
  846.                             this.recipeChache.getRecipe().get(craftingRecipes).getAmount3() + 1 : this.recipeChache.getRecipe().get(craftingRecipes).getAmount3()))
  847.                         return true;
  848.                 }
  849.             }
  850.         return false;
  851.     }
  852.  
  853.     /**
  854.      * Check the amount of item one type or if recipe has several diffrent matrial it can use
  855.      * it include even this from the inventory.
  856.      * <p>
  857.      * Like for example planks has several wood types, but you can use several diffrent type´s to craft
  858.      * an item.
  859.      *
  860.      * @param itemsInsideInventory the items you have inside the inventory
  861.      * @param craftingRecipes      the recipe ingridient you want to match aginst.
  862.      * @param itemUsedToCrafting   the item some you want to check (in this case I use it fot colors some has diffrent recipe)
  863.      * @return true if it equal or more items inside the inventory.
  864.      */
  865.     public boolean checkAmountForRecipeFourth(Map<Material, ItemStack> itemsInsideInventory, ItemStack craftingRecipes, Material... itemUsedToCrafting) {
  866.         int itemAmount = 0;
  867.  
  868.         boolean matchedItem = false;
  869.         if (itemUsedToCrafting != null)
  870.             for (Material items : itemUsedToCrafting)
  871.                 if (items == Material.WHITE_DYE || items == Material.BONE_MEAL) {
  872.                     matchedItem = true;
  873.                     break;
  874.                 }
  875.  
  876.         if (itemsInsideInventory != null && craftingRecipes != null)
  877.             for (Map.Entry<Material, ItemStack> item : itemsInsideInventory.entrySet()) {
  878.                 if (item.getValue().getType() == splitIngrediens(item.getValue().getType(), this.recipeChache.getRecipe().get(craftingRecipes).getMatrial4())) {
  879.                     itemAmount += item.getValue().getAmount();
  880.                     if (itemAmount >= this.recipeChache.getRecipe().get(craftingRecipes).getAmount4())
  881.                         return true;
  882.                 }
  883.             }
  884.         return false;
  885.     }
  886.  
  887.     /**
  888.      * Check the amount of item one type or if recipe has several diffrent matrial it can use
  889.      * it include even this from the inventory.
  890.      * <p>
  891.      * Like for example planks has several wood types, but you can use several diffrent type´s to craft
  892.      * an item.
  893.      *
  894.      * @param itemsInsideInventory the items you have inside the inventory
  895.      * @param craftingRecipes      the recipe ingridient you want to match aginst.
  896.      * @param itemUsedToCrafting   the item some you want to check (in this case I use it fot colors some has diffrent recipe)
  897.      * @return true if it equal or more items inside the inventory.
  898.      */
  899.     public boolean checkAmountForRecipeFifth(Map<Material, ItemStack> itemsInsideInventory, ItemStack craftingRecipes, Material... itemUsedToCrafting) {
  900.         int itemAmount = 0;
  901.  
  902.         boolean matchedItem = false;
  903.         if (itemUsedToCrafting != null)
  904.             for (Material items : itemUsedToCrafting)
  905.                 if (items == Material.WHITE_DYE || items == Material.BONE_MEAL) {
  906.                     matchedItem = true;
  907.                     break;
  908.                 }
  909.  
  910.         if (itemsInsideInventory != null && craftingRecipes != null)
  911.             for (Map.Entry<Material, ItemStack> item : itemsInsideInventory.entrySet()) {
  912.                 if (item.getValue().getType() == splitIngrediens(item.getValue().getType(), this.recipeChache.getRecipe().get(craftingRecipes).getMatrial5())) {
  913.                     itemAmount += item.getValue().getAmount();
  914.                     if (itemAmount >= this.recipeChache.getRecipe().get(craftingRecipes).getAmount5())
  915.                         return true;
  916.                 }
  917.             }
  918.         return false;
  919.     }
  920.  
  921.     /**
  922.      * Get the contents of a specific location and see what was crafted.
  923.      *
  924.      * @param location of the container some crafted the items.
  925.      * @return Itemstack of the crafted items.
  926.      */
  927.  
  928.     public Map<ItemStack, ItemStack> getCraftedItems(Location location) {
  929.         return craftedItems.get(location);
  930.     }
  931.  
  932.     /**
  933.      * Get all the contents crafted on all locations.
  934.      *
  935.      * @return The map contents.
  936.      */
  937.     public Map<Location, Map<ItemStack, ItemStack>> getCraftedItems() {
  938.         return craftedItems;
  939.     }
  940.  
  941.     /**
  942.      * Remove crafted items on one location.
  943.      *
  944.      * @param location of the container some crafted the items.
  945.      */
  946.  
  947.     public void removeCraftedItems(Location location) {
  948.         craftedItems.remove(location);
  949.     }
  950. }
  951.  
RAW Paste Data