broken-arrow

Untitled

Sep 17th, 2021
831
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.     private Map<ItemStack, RecipeData> recipesCache = new HashMap<>();
  15.  
  16.     /**
  17.      *  add the recipe tho the cache.
  18.      *  
  19.      * @param recipes the output item
  20.      * @param material1 matrials used
  21.      * @param material2 matrials used
  22.      * @param material3 matrials used
  23.      * @param material4 matrials used
  24.      * @param material5 matrials used
  25.      * @param amount1 amount of matrials used
  26.      * @param amount2 amount of matrials used
  27.      * @param amount3 amount of matrials used
  28.      * @param amount4 amount of matrials used
  29.      * @param amount5 amount of matrials used
  30.      */
  31.    
  32.    
  33.     public void addRecipes(ItemStack recipes, Set<ItemStack> material1, Set<ItemStack> material2, Set<ItemStack> material3, Set<ItemStack> material4, Set<ItemStack> material5,
  34.                            int amount1, int amount2, int amount3, int amount4, int amount5) {
  35.         this.recipesCache.put(recipes, RecipeData.of(material1, material2, material3, material4, material5,
  36.                 amount1, amount2, amount3, amount4, amount5));
  37.  
  38.     }
  39.  
  40.     /**
  41.      * Get the map with all recipes
  42.      *
  43.      * @return return all recipes.
  44.      */
  45.  
  46.     public Map<ItemStack, RecipeData> getRecipe() {
  47.         return this.recipesCache;
  48.     }
  49.  
  50.     /**
  51.      * Get all recipes as a setlist
  52.      *
  53.      * @return a list of recipes.
  54.      */
  55.    
  56.     public Set<ItemStack> getRecipes() {
  57.         return this.recipesCache.keySet();
  58.     }
  59.    
  60.     /**
  61.      * Get one recipe from this cache
  62.      *
  63.      * @param recipe the recipe you want the ingridens.
  64.      * @return the recipe ingridens.
  65.      */
  66.  
  67.     public RecipeData getRecipe(ItemStack recipe) {
  68.         return this.recipesCache.get(recipe);
  69.     }
  70.  
  71.     public static class RecipeData implements ConfigSerializable {
  72.  
  73.         Set<ItemStack> matrial1;
  74.         Set<ItemStack> matrial2;
  75.         Set<ItemStack> matrial3;
  76.         Set<ItemStack> matrial4;
  77.         Set<ItemStack> matrial5;
  78.  
  79.         int amount1;
  80.         int amount2;
  81.         int amount3;
  82.         int amount4;
  83.         int amount5;
  84.  
  85.         public RecipeData() {
  86.         }
  87.  
  88.         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) {
  89.  
  90.             this.matrial1 = matrial1;
  91.             this.matrial2 = matrial2;
  92.             this.matrial3 = matrial3;
  93.             this.matrial4 = matrial4;
  94.             this.matrial5 = matrial5;
  95.             this.amount1 = amount1;
  96.             this.amount2 = amount2;
  97.             this.amount3 = amount3;
  98.             this.amount4 = amount4;
  99.             this.amount5 = amount5;
  100.         }
  101.  
  102.         @Override
  103.         public SerializedMap serialize() {
  104.             final SerializedMap map = new SerializedMap();
  105.  
  106.  
  107.             map.put("Matrial1", this.matrial1);
  108.             map.put("Matrial2", this.matrial2);
  109.             map.put("Matrial3", this.matrial3);
  110.             map.put("Matrial4", this.matrial4);
  111.             map.put("Matrial5", this.matrial5);
  112.             map.put("Amount1", this.amount1);
  113.             map.put("Amount2", this.amount2);
  114.             map.put("Amount3", this.amount3);
  115.             map.put("Amount4", this.amount4);
  116.             map.put("Amount5", this.amount5);
  117.  
  118.             return map;
  119.         }
  120.  
  121.  
  122.         static RecipeData of(Set<ItemStack> matrial1, Set<ItemStack> matrial2, Set<ItemStack> matrial3, Set<ItemStack> matrial4,
  123.                              Set<ItemStack> matrial5, int amount1, int amount2, int amount3, int amount4, int amount5) {
  124.             RecipeData data = new RecipeData();
  125.  
  126.             data.matrial1 = matrial1;
  127.             data.matrial2 = matrial2;
  128.             data.matrial3 = matrial3;
  129.             data.matrial4 = matrial4;
  130.             data.matrial5 = matrial5;
  131.             data.amount1 = amount1;
  132.             data.amount2 = amount2;
  133.             data.amount3 = amount3;
  134.             data.amount4 = amount4;
  135.             data.amount5 = amount5;
  136.  
  137.             return data;
  138.         }
  139.  
  140.         @Override
  141.         public String toString() {
  142.             return FormattingMaps.toStringFormatted(serialize());
  143.         }
  144.  
  145.  
  146.     }
  147.  
  148. }
  149.  
RAW Paste Data