Class RecipeUtil

java.lang.Object
me.mehboss.utils.RecipeUtil

public class RecipeUtil extends Object
Utility manager and API entry point for creating, validating, and storing custom recipe definitions inside the CustomRecipes plugin.

This class maintains several internal collections used by the plugin:

  • recipes: A map of recipe names to their corresponding RecipeUtil.Recipe objects.
  • keyList: A list of all registered NamespacedKey identifiers.
  • custom_items: A lookup table for custom ItemStacks used by recipes.
  • SUPPORTED_PLUGINS: A list of optional hookable item systems (ItemsAdder, MythicMobs, ExecutableItems, Oraxen, Nexo, MMOItems).

Recipe Registration

The createRecipe(Recipe) method is the primary entry point for adding recipes to CustomRecipes. Before a recipe is accepted, it is validated against several rules — if any fail, an InvalidRecipeException is thrown with a descriptive error message.

Validation rules include:

  • Null or missing key: The recipe must not be null and must have a valid NamespacedKey.
  • Ingredient count: Shaped / shapeless recipes must contain exactly 9 ingredient slots.
  • Result validity: The output item must exist and cannot be AIR.
  • Shape integrity: Shaped recipes must have non-null rows (1–3).
  • Single-input rules: Furnace / stonecutter recipes may only have 1 ingredient.

When validation passes, the recipe is stored internally and becomes retrievable by name or its associated key.

This class is intended for use by addon developers and internal systems that need programmatic control over recipe creation and management.

  • Field Details

    • SUPPORTED_PLUGINS

      public List<String> SUPPORTED_PLUGINS
  • Constructor Details

    • RecipeUtil

      public RecipeUtil()
  • Method Details

    • createRecipe

      public void createRecipe(RecipeUtil.Recipe recipe)
      Adds a finished Recipe object to the API
      Parameters:
      recipe - the Recipe object
      Throws:
      InvalidRecipeException - if the recipe is null or no NamespacedKey has been set
      InvalidRecipeException - if the crafting recipe does not have 9 ingredients
      InvalidRecipeException - if the furnace or stone cutter has more than 1 ingredient
      InvalidRecipeException - if the result is null or air
      InvalidRecipeException - if the row shape of the shaped recipe is null
    • removeRecipe

      public void removeRecipe(String recipeName)
      Removes a recipe registered with CR.
      Parameters:
      recipeName - the string name of the recipe you wanting to remove.
    • registerRecipe

      public void registerRecipe(RecipeUtil.Recipe recipe)
      Loads the specified recipe to the server. Checks and corrects duplicate NamespacedKey.
      Parameters:
      recipe - the recipe you want to load
    • reloadRecipes

      public void reloadRecipes()
      Resets and reloads all registered recipes, including CR recipes. Checks and corrects duplicate NamespacedKey.
    • getCustomItemPlugin

      public String getCustomItemPlugin(String key)
      Extracts the plugin namespace from a custom item key.

      Custom item keys typically follow the format:

       pluginNamespace:itemId
       
      Parameters:
      key - the full custom item key (e.g. "mmoitems:SWORD_1")
      Returns:
      the namespace before the colon, or null if the key is invalid.
    • isCustomItem

      public Boolean isCustomItem(String key)
      Checks whether a namespace belongs to a supported custom-item plugin.

      This only validates the namespace string (e.g. "mmoitems") — it does not check if the plugin is installed or if the item exists.

      Parameters:
      key - the plugin namespace to check
      Returns:
      true if the namespace matches a known custom-item plugin.
    • getResultFromKey

      public org.bukkit.inventory.ItemStack getResultFromKey(String key)
      Getter for a result from a namespaced key.
      Parameters:
      key - the NamespacedKey as a String (e.g., itemsadder:my_item)
      Returns:
      the ItemStack if found, can be null
    • getKeyFromResult

      public String getKeyFromResult(org.bukkit.inventory.ItemStack item)
      Getter for a key from the result ItemStack
      Parameters:
      item - the ItemStack
      Returns:
      the key that is found, can be null
    • getRecipeFromKey

      public RecipeUtil.Recipe getRecipeFromKey(String key)
      Getter for a recipe from Namespacedkey
      Parameters:
      key - the NamespacedKey
      Returns:
      the Recipe that is found, can be null
    • getRecipe

      public RecipeUtil.Recipe getRecipe(String recipeName)
      Getter for a recipe from the Name
      Parameters:
      recipeName - the recipe name
      Returns:
      the Recipe that is found, can be null
    • getRecipeFromResult

      public RecipeUtil.Recipe getRecipeFromResult(org.bukkit.inventory.ItemStack item)
      Getter for a recipe from the result ItemStack
      Parameters:
      item - the ItemStack
      Returns:
      the Recipe that is found, can be null
    • getAllRecipes

      public HashMap<String,RecipeUtil.Recipe> getAllRecipes()
      Getter for all recipes registered
      Returns:
      a hashmap of recipes, including CR recipes, can be null
    • getAllRecipesSortedByResult

      public List<RecipeUtil.Recipe> getAllRecipesSortedByResult(org.bukkit.inventory.ItemStack shown)
      Get all recipes, ordered so that any recipes whose result is similar to the given result item are first.
      Parameters:
      shown - the result item in the crafting inventory (can be null or AIR)
      Returns:
      ordered list of recipes
    • getRecipesFromType

      public HashMap<String,RecipeUtil.Recipe> getRecipesFromType(RecipeUtil.Recipe.RecipeType type)
      Getter for all recipes matching a type
      Parameters:
      type - the recipe type
      Returns:
      the hashmap of recipes found, can be null
    • getAllResults

      public ArrayList<org.bukkit.inventory.ItemStack> getAllResults()
      Getter for all recipe results
      Returns:
      an arraylist of recipe ItemStacks
    • getRecipeNames

      public ArrayList<String> getRecipeNames()
      Getter for all recipe names
      Returns:
      a set of strings
    • getRecipeFromFurnaceSource

      public RecipeUtil.Recipe getRecipeFromFurnaceSource(org.bukkit.inventory.ItemStack item)
      Getter for a furnace recipe by the source
      Returns:
      recipe the recipe that matches