diff --git a/paper-api/src/main/java/org/bukkit/inventory/CraftingRecipe.java b/paper-api/src/main/java/org/bukkit/inventory/CraftingRecipe.java
index e4bf772f7..1b7b07715 100644
--- a/paper-api/src/main/java/org/bukkit/inventory/CraftingRecipe.java
+++ b/paper-api/src/main/java/org/bukkit/inventory/CraftingRecipe.java
@@ -5,6 +5,7 @@ import org.bukkit.Keyed;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.recipe.CraftingBookCategory;
+import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
@@ -18,7 +19,6 @@ public abstract class CraftingRecipe implements Recipe, Keyed {
protected CraftingRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result) {
Preconditions.checkArgument(key != null, "key cannot be null");
- Preconditions.checkArgument(result.getType() != Material.AIR, "Recipe must have non-AIR result.");
this.key = key;
this.output = new ItemStack(result);
}
@@ -65,7 +65,7 @@ public abstract class CraftingRecipe implements Recipe, Keyed {
/**
* Gets the category which this recipe will appear in the recipe book under.
- *
+ *
* Defaults to {@link CraftingBookCategory#MISC} if not set.
*
* @return recipe book category
@@ -77,7 +77,7 @@ public abstract class CraftingRecipe implements Recipe, Keyed {
/**
* Sets the category which this recipe will appear in the recipe book under.
- *
+ *
* Defaults to {@link CraftingBookCategory#MISC} if not set.
*
* @param category recipe book category
@@ -86,4 +86,20 @@ public abstract class CraftingRecipe implements Recipe, Keyed {
Preconditions.checkArgument(category != null, "category cannot be null");
this.category = category;
}
+
+ /**
+ * Checks an ItemStack to be used in constructors related to CraftingRecipe
+ * is not empty.
+ *
+ * @param result an ItemStack
+ * @return the same result ItemStack
+ * @throws IllegalArgumentException if the {@code result} is an empty item
+ * (AIR)
+ */
+ @ApiStatus.Internal
+ @NotNull
+ protected static ItemStack checkResult(@NotNull ItemStack result) {
+ Preconditions.checkArgument(result.getType() != Material.AIR, "Recipe must have non-AIR result.");
+ return result;
+ }
}
diff --git a/paper-api/src/main/java/org/bukkit/inventory/ShapedRecipe.java b/paper-api/src/main/java/org/bukkit/inventory/ShapedRecipe.java
index a601bc38e..16c10d75d 100644
--- a/paper-api/src/main/java/org/bukkit/inventory/ShapedRecipe.java
+++ b/paper-api/src/main/java/org/bukkit/inventory/ShapedRecipe.java
@@ -32,7 +32,7 @@ public class ShapedRecipe extends CraftingRecipe {
*/
@Deprecated
public ShapedRecipe(@NotNull ItemStack result) {
- super(NamespacedKey.randomKey(), result);
+ this(NamespacedKey.randomKey(), result);
}
/**
@@ -42,6 +42,7 @@ public class ShapedRecipe extends CraftingRecipe {
*
* @param key the unique recipe key
* @param result The item you want the recipe to create.
+ * @exception IllegalArgumentException if the {@code result} is an empty item (AIR)
* @see ShapedRecipe#shape(String...)
* @see ShapedRecipe#setIngredient(char, Material)
* @see ShapedRecipe#setIngredient(char, Material, int)
@@ -49,7 +50,7 @@ public class ShapedRecipe extends CraftingRecipe {
* @see ShapedRecipe#setIngredient(char, RecipeChoice)
*/
public ShapedRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result) {
- super(key, result);
+ super(key, checkResult(result));
}
/**
diff --git a/paper-api/src/main/java/org/bukkit/inventory/ShapelessRecipe.java b/paper-api/src/main/java/org/bukkit/inventory/ShapelessRecipe.java
index 3d50775da..bc924ae23 100644
--- a/paper-api/src/main/java/org/bukkit/inventory/ShapelessRecipe.java
+++ b/paper-api/src/main/java/org/bukkit/inventory/ShapelessRecipe.java
@@ -19,7 +19,7 @@ public class ShapelessRecipe extends CraftingRecipe {
@Deprecated
public ShapelessRecipe(@NotNull ItemStack result) {
- super(NamespacedKey.randomKey(), result);
+ this(NamespacedKey.randomKey(), result);
}
/**
@@ -29,6 +29,7 @@ public class ShapelessRecipe extends CraftingRecipe {
*
* @param key the unique recipe key
* @param result The item you want the recipe to create.
+ * @exception IllegalArgumentException if the {@code result} is an empty item (AIR)
* @see ShapelessRecipe#addIngredient(Material)
* @see ShapelessRecipe#addIngredient(MaterialData)
* @see ShapelessRecipe#addIngredient(Material,int)
@@ -37,7 +38,7 @@ public class ShapelessRecipe extends CraftingRecipe {
* @see ShapelessRecipe#addIngredient(int,Material,int)
*/
public ShapelessRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result) {
- super(key, result);
+ super(key, checkResult(result));
}
/**