Commits
Doc authored and md_5 committed 2ec53f498e3
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( NamespacedKey key, 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 | |
27 27 | |
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( 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 | |
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( 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 + | Internal | .
100 + | |
101 + | protected static ItemStack checkResult( ItemStack result) { |
102 + | Preconditions.checkArgument(result.getType() != Material.AIR, "Recipe must have non-AIR result."); |
103 + | return result; |
104 + | } |
89 105 | } |