mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-09 00:22:08 -07:00
#1050: Fix empty result check for Complex Recipes
By: Doc <nachito94@msn.com> Also-by: Bjarne Koll <lynxplay101@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import org.bukkit.Keyed;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.inventory.recipe.CraftingBookCategory;
|
import org.bukkit.inventory.recipe.CraftingBookCategory;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,7 +19,6 @@ public abstract class CraftingRecipe implements Recipe, Keyed {
|
|||||||
|
|
||||||
protected CraftingRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result) {
|
protected CraftingRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result) {
|
||||||
Preconditions.checkArgument(key != null, "key cannot be null");
|
Preconditions.checkArgument(key != null, "key cannot be null");
|
||||||
Preconditions.checkArgument(result.getType() != Material.AIR, "Recipe must have non-AIR result.");
|
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.output = new ItemStack(result);
|
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.
|
* Gets the category which this recipe will appear in the recipe book under.
|
||||||
*
|
* <br>
|
||||||
* Defaults to {@link CraftingBookCategory#MISC} if not set.
|
* Defaults to {@link CraftingBookCategory#MISC} if not set.
|
||||||
*
|
*
|
||||||
* @return recipe book category
|
* @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.
|
* Sets the category which this recipe will appear in the recipe book under.
|
||||||
*
|
* <br>
|
||||||
* Defaults to {@link CraftingBookCategory#MISC} if not set.
|
* Defaults to {@link CraftingBookCategory#MISC} if not set.
|
||||||
*
|
*
|
||||||
* @param category recipe book category
|
* @param category recipe book category
|
||||||
@@ -86,4 +86,20 @@ public abstract class CraftingRecipe implements Recipe, Keyed {
|
|||||||
Preconditions.checkArgument(category != null, "category cannot be null");
|
Preconditions.checkArgument(category != null, "category cannot be null");
|
||||||
this.category = category;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,7 @@ public class ShapedRecipe extends CraftingRecipe {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public ShapedRecipe(@NotNull ItemStack result) {
|
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 key the unique recipe key
|
||||||
* @param result The item you want the recipe to create.
|
* @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#shape(String...)
|
||||||
* @see ShapedRecipe#setIngredient(char, Material)
|
* @see ShapedRecipe#setIngredient(char, Material)
|
||||||
* @see ShapedRecipe#setIngredient(char, Material, int)
|
* @see ShapedRecipe#setIngredient(char, Material, int)
|
||||||
@@ -49,7 +50,7 @@ public class ShapedRecipe extends CraftingRecipe {
|
|||||||
* @see ShapedRecipe#setIngredient(char, RecipeChoice)
|
* @see ShapedRecipe#setIngredient(char, RecipeChoice)
|
||||||
*/
|
*/
|
||||||
public ShapedRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result) {
|
public ShapedRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result) {
|
||||||
super(key, result);
|
super(key, checkResult(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -19,7 +19,7 @@ public class ShapelessRecipe extends CraftingRecipe {
|
|||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public ShapelessRecipe(@NotNull ItemStack result) {
|
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 key the unique recipe key
|
||||||
* @param result The item you want the recipe to create.
|
* @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(Material)
|
||||||
* @see ShapelessRecipe#addIngredient(MaterialData)
|
* @see ShapelessRecipe#addIngredient(MaterialData)
|
||||||
* @see ShapelessRecipe#addIngredient(Material,int)
|
* @see ShapelessRecipe#addIngredient(Material,int)
|
||||||
@@ -37,7 +38,7 @@ public class ShapelessRecipe extends CraftingRecipe {
|
|||||||
* @see ShapelessRecipe#addIngredient(int,Material,int)
|
* @see ShapelessRecipe#addIngredient(int,Material,int)
|
||||||
*/
|
*/
|
||||||
public ShapelessRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result) {
|
public ShapelessRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result) {
|
||||||
super(key, result);
|
super(key, checkResult(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user