broken-arrow

Untitled

Sep 26th, 2021
1,005
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.broken.cheststorage.Crafting;
  2.  
  3. import org.broken.cheststorage.util.FormattingMaps;
  4. import org.bukkit.inventory.ItemStack;
  5. import org.mineacademy.fo.collection.SerializedMap;
  6. import org.mineacademy.fo.model.ConfigSerializable;
  7.  
  8. import java.util.HashMap;
  9. import java.util.Map;
  10. import java.util.Set;
  11.  
  12. public class RecipeCache {
  13.  
  14.  
  15.     private Map<ItemStack, RecipeData> recipesCache = new HashMap<>();
  16.  
  17.     /**
  18.      * add the recipe tho the cache.
  19.      *
  20.      * @param recipes     the output item
  21.      * @param material1   matrials used
  22.      * @param material2   matrials used
  23.      * @param material3   matrials used
  24.      * @param material4   matrials used
  25.      * @param material5   matrials used
  26.      * @param amount1     amount of matrials used
  27.      * @param amount2     amount of matrials used
  28.      * @param amount3     amount of matrials used
  29.      * @param amount4     amount of matrials used
  30.      * @param amount5     amount of matrials used
  31.      * @param totalAmount of matrials used
  32.      */
  33.  
  34.  
  35.     public void addRecipes(ItemStack recipes, Set<ItemStack> material1, Set<ItemStack> material2, Set<ItemStack> material3, Set<ItemStack> material4, Set<ItemStack> material5,
  36.                            int amount1, int amount2, int amount3, int amount4, int amount5, int totalAmount) {
  37.         this.recipesCache.put(recipes, RecipeData.of(material1, material2, material3, material4, material5,
  38.                 amount1, amount2, amount3, amount4, amount5, totalAmount));
  39.  
  40.     }
  41.  
  42.     /**
  43.      * Get the map with all recipes
  44.      *
  45.      * @return return all recipes.
  46.      */
  47.  
  48.     public Map<ItemStack, RecipeData> getRecipe() {
  49.         return this.recipesCache;
  50.     }
  51.  
  52.     /**
  53.      * Get all recipes as a setlist
  54.      *
  55.      * @return a list of recipes.
  56.      */
  57.  
  58.     public Set<ItemStack> getRecipes() {
  59.         return this.recipesCache.keySet();
  60.     }
  61.  
  62.     /**
  63.      * Get one recipe from this cache
  64.      *
  65.      * @param recipe the recipe you want the ingridens.
  66.      * @return the recipe ingridens.
  67.      */
  68.  
  69.     public RecipeData getRecipe(ItemStack recipe) {
  70.         return this.recipesCache.get(recipe);
  71.     }
  72.  
  73.     public static class RecipeData implements ConfigSerializable {
  74.  
  75.         Set<ItemStack> matrial1;
  76.         Set<ItemStack> matrial2;
  77.         Set<ItemStack> matrial3;
  78.         Set<ItemStack> matrial4;
  79.         Set<ItemStack> matrial5;
  80.  
  81.         int amount1;
  82.         int amount2;
  83.         int amount3;
  84.         int amount4;
  85.         int amount5;
  86.         int totalAmount;
  87.  
  88.         public RecipeData() {
  89.         }
  90.  
  91.         public RecipeData(Set<ItemStack> matrial1, Set<ItemStack> matrial2, Set<ItemStack> matrial3, Set<ItemStack> matrial4, Set<ItemStack> matrial5, int amount1, int amount2, int amount3, int amount4, int amount5, int totalAmount) {
  92.  
  93.             this.matrial1 = matrial1;
  94.             this.matrial2 = matrial2;
  95.             this.matrial3 = matrial3;
  96.             this.matrial4 = matrial4;
  97.             this.matrial5 = matrial5;
  98.             this.amount1 = amount1;
  99.             this.amount2 = amount2;
  100.             this.amount3 = amount3;
  101.             this.amount4 = amount4;
  102.             this.amount5 = amount5;
  103.             this.totalAmount = totalAmount;
  104.         }
  105.  
  106.         @Override
  107.         public SerializedMap serialize() {
  108.             final SerializedMap map = new SerializedMap();
  109.  
  110.  
  111.             map.put("Matrial1", this.matrial1);
  112.             map.put("Matrial2", this.matrial2);
  113.             map.put("Matrial3", this.matrial3);
  114.             map.put("Matrial4", this.matrial4);
  115.             map.put("Matrial5", this.matrial5);
  116.             map.put("Amount1", this.amount1);
  117.             map.put("Amount2", this.amount2);
  118.             map.put("Amount3", this.amount3);
  119.             map.put("Amount4", this.amount4);
  120.             map.put("Amount5", this.amount5);
  121.             map.put("totalAmount", this.totalAmount);
  122.  
  123.             return map;
  124.         }
  125.  
  126.  
  127.         static RecipeData of(Set<ItemStack> matrial1, Set<ItemStack> matrial2, Set<ItemStack> matrial3, Set<ItemStack> matrial4,
  128.                              Set<ItemStack> matrial5, int amount1, int amount2, int amount3, int amount4, int amount5, int totalAmount) {
  129.             RecipeData data = new RecipeData();
  130.  
  131.             data.matrial1 = matrial1;
  132.             data.matrial2 = matrial2;
  133.             data.matrial3 = matrial3;
  134.             data.matrial4 = matrial4;
  135.             data.matrial5 = matrial5;
  136.             data.amount1 = amount1;
  137.             data.amount2 = amount2;
  138.             data.amount3 = amount3;
  139.             data.amount4 = amount4;
  140.             data.amount5 = amount5;
  141.             data.totalAmount = totalAmount;
  142.  
  143.             return data;
  144.         }
  145.  
  146.         @Override
  147.         public String toString() {
  148.             return FormattingMaps.toStringFormatted(serialize());
  149.         }
  150.  
  151.         public Set<ItemStack> getMatrial1() {
  152.             return matrial1;
  153.         }
  154.  
  155.         public Set<ItemStack> getMatrial2() {
  156.             return matrial2;
  157.         }
  158.  
  159.         public Set<ItemStack> getMatrial3() {
  160.             return matrial3;
  161.         }
  162.  
  163.         public Set<ItemStack> getMatrial4() {
  164.             return matrial4;
  165.         }
  166.  
  167.         public Set<ItemStack> getMatrial5() {
  168.             return matrial5;
  169.         }
  170.  
  171.         public int getAmount1() {
  172.             return amount1;
  173.         }
  174.  
  175.         public int getAmount2() {
  176.             return amount2;
  177.         }
  178.  
  179.         public int getAmount3() {
  180.             return amount3;
  181.         }
  182.  
  183.         public int getAmount4() {
  184.             return amount4;
  185.         }
  186.  
  187.         public int getAmount5() {
  188.             return amount5;
  189.         }
  190.  
  191.         public int getTotalAmount() {
  192.             return totalAmount;
  193.         }
  194.     }
  195.  
  196. }
  197.  
RAW Paste Data