Class RecipeUtil
This class maintains several internal collections used by the plugin:
- recipes: A map of recipe names to their corresponding
RecipeUtil.Recipeobjects. - keyList: A list of all registered
NamespacedKeyidentifiers. - 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a single ingredient used in a recipe.static classRepresents a fully defined custom recipe used by the CustomRecipes API. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateRecipe(RecipeUtil.Recipe recipe) Adds a finished Recipe object to the APIGetter for all recipes registeredgetAllRecipesSortedByResult(org.bukkit.inventory.ItemStack shown) Get all recipes, ordered so that any recipes whose result is similar to the given result item are first.ArrayList<org.bukkit.inventory.ItemStack> Getter for all recipe resultsExtracts the plugin namespace from a custom item key.getKeyFromResult(org.bukkit.inventory.ItemStack item) Getter for a key from the result ItemStackGetter for a recipe from the NamegetRecipeFromFurnaceSource(org.bukkit.inventory.ItemStack item) Getter for a furnace recipe by the sourcegetRecipeFromKey(String key) Getter for a recipe from NamespacedkeygetRecipeFromResult(org.bukkit.inventory.ItemStack item) Getter for a recipe from the result ItemStackGetter for all recipe namesGetter for all recipes matching a typeorg.bukkit.inventory.ItemStackgetResultFromKey(String key) Getter for a result from a namespaced key.isCustomItem(String key) Checks whether a namespace belongs to a supported custom-item plugin.voidregisterRecipe(RecipeUtil.Recipe recipe) Loads the specified recipe to the server.voidResets and reloads all registered recipes, including CR recipes.voidremoveRecipe(String recipeName) Removes a recipe registered with CR.
-
Field Details
-
SUPPORTED_PLUGINS
-
-
Constructor Details
-
RecipeUtil
public RecipeUtil()
-
-
Method Details
-
createRecipe
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 setInvalidRecipeException- if the crafting recipe does not have 9 ingredientsInvalidRecipeException- if the furnace or stone cutter has more than 1 ingredientInvalidRecipeException- if the result is null or airInvalidRecipeException- if the row shape of the shaped recipe is null
-
removeRecipe
Removes a recipe registered with CR.- Parameters:
recipeName- the string name of the recipe you wanting to remove.
-
registerRecipe
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
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
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
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
Getter for a key from the result ItemStack- Parameters:
item- the ItemStack- Returns:
- the key that is found, can be null
-
getRecipeFromKey
Getter for a recipe from Namespacedkey- Parameters:
key- the NamespacedKey- Returns:
- the Recipe that is found, can be null
-
getRecipe
Getter for a recipe from the Name- Parameters:
recipeName- the recipe name- Returns:
- the Recipe that is found, can be null
-
getRecipeFromResult
Getter for a recipe from the result ItemStack- Parameters:
item- the ItemStack- Returns:
- the Recipe that is found, can be null
-
getAllRecipes
Getter for all recipes registered- Returns:
- a hashmap of recipes, including CR recipes, can be null
-
getAllRecipesSortedByResult
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
Getter for all recipes matching a type- Parameters:
type- the recipe type- Returns:
- the hashmap of recipes found, can be null
-
getAllResults
Getter for all recipe results- Returns:
- an arraylist of recipe ItemStacks
-
getRecipeNames
-
getRecipeFromFurnaceSource
Getter for a furnace recipe by the source- Returns:
- recipe the recipe that matches
-