broken-arrow

Untitled

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