1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2025-02-18 11:22:15 +01:00

: Fix empty result check for Complex Recipes

By: Doc <nachito94@msn.com>
Also-by: Bjarne Koll <lynxplay101@gmail.com>
This commit is contained in:
Bukkit/Spigot 2024-08-01 07:53:56 +10:00
parent bc71bebfb4
commit 4378d2ea30
3 changed files with 25 additions and 7 deletions
paper-api/src/main/java/org/bukkit/inventory

View file

@ -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.
*
* <br>
* 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.
*
* <br>
* 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;
}
}

View file

@ -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));
}
/**

View file

@ -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));
}
/**