Advertisement
broken-arrow

Untitled

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