Commits

Doc authored and md_5 committed 2ec53f498e3
#1050: Fix empty result check for Complex Recipes

Co-authored-by: Bjarne Koll <lynxplay101@gmail.com>
No tags

src/main/java/org/bukkit/inventory/CraftingRecipe.java

Modified
1 1 package org.bukkit.inventory;
2 2
3 3 import com.google.common.base.Preconditions;
4 4 import org.bukkit.Keyed;
5 5 import org.bukkit.Material;
6 6 import org.bukkit.NamespacedKey;
7 7 import org.bukkit.inventory.recipe.CraftingBookCategory;
8 +import org.jetbrains.annotations.ApiStatus;
8 9 import org.jetbrains.annotations.NotNull;
9 10
10 11 /**
11 12 * Represents a shaped or shapeless crafting recipe.
12 13 */
13 14 public abstract class CraftingRecipe implements Recipe, Keyed {
14 15 private final NamespacedKey key;
15 16 private final ItemStack output;
16 17 private String group = "";
17 18 private CraftingBookCategory category = CraftingBookCategory.MISC;
18 19
19 20 protected CraftingRecipe(@NotNull NamespacedKey key, @NotNull ItemStack result) {
20 21 Preconditions.checkArgument(key != null, "key cannot be null");
21 - Preconditions.checkArgument(result.getType() != Material.AIR, "Recipe must have non-AIR result.");
22 22 this.key = key;
23 23 this.output = new ItemStack(result);
24 24 }
25 25
26 26 @NotNull
27 27 @Override
28 28 public NamespacedKey getKey() {
29 29 return key;
30 30 }
31 31
58 58 * @param group recipe group. An empty string denotes no group. May not be
59 59 * null.
60 60 */
61 61 public void setGroup(@NotNull String group) {
62 62 Preconditions.checkArgument(group != null, "group cannot be null");
63 63 this.group = group;
64 64 }
65 65
66 66 /**
67 67 * Gets the category which this recipe will appear in the recipe book under.
68 - *
68 + * <br>
69 69 * Defaults to {@link CraftingBookCategory#MISC} if not set.
70 70 *
71 71 * @return recipe book category
72 72 */
73 73 @NotNull
74 74 public CraftingBookCategory getCategory() {
75 75 return category;
76 76 }
77 77
78 78 /**
79 79 * Sets the category which this recipe will appear in the recipe book under.
80 - *
80 + * <br>
81 81 * Defaults to {@link CraftingBookCategory#MISC} if not set.
82 82 *
83 83 * @param category recipe book category
84 84 */
85 85 public void setCategory(@NotNull CraftingBookCategory category) {
86 86 Preconditions.checkArgument(category != null, "category cannot be null");
87 87 this.category = category;
88 88 }
89 +
90 + /**
91 + * Checks an ItemStack to be used in constructors related to CraftingRecipe
92 + * is not empty.
93 + *
94 + * @param result an ItemStack
95 + * @return the same result ItemStack
96 + * @throws IllegalArgumentException if the {@code result} is an empty item
97 + * (AIR)
98 + */
99 + @ApiStatus.Internal
100 + @NotNull
101 + protected static ItemStack checkResult(@NotNull ItemStack result) {
102 + Preconditions.checkArgument(result.getType() != Material.AIR, "Recipe must have non-AIR result.");
103 + return result;
104 + }
89 105 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut