Commits

Parker Hawke authored and md_5 committed 53fa4f726fe
#1011: Throw an exception if a RecipeChoice is ever supplied air

This would otherwise crash the client.
No tags

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

Modified
6 6 import java.util.Collections;
7 7 import java.util.List;
8 8 import java.util.Objects;
9 9 import java.util.function.Predicate;
10 10 import org.bukkit.Material;
11 11 import org.bukkit.Tag;
12 12 import org.jetbrains.annotations.NotNull;
13 13
14 14 /**
15 15 * Represents a potential item match within a recipe. All choices within a
16 - * recipe must be satisfied for it to be craftable.
16 + * recipe must be satisfied for it to be craftable. Choices must never be
17 + * null or air.
17 18 *
18 19 * <b>This class is not legal for implementation by plugins!</b>
19 20 */
20 21 public interface RecipeChoice extends Predicate<ItemStack>, Cloneable {
21 22
22 23 /**
23 24 * Gets a single item stack representative of this stack choice.
24 25 *
25 26 * @return a single representative item
26 27 * @deprecated for compatibility only
59 60 public MaterialChoice(@NotNull Tag<Material> choices) {
60 61 Preconditions.checkArgument(choices != null, "choices");
61 62 this.choices = new ArrayList<>(choices.getValues());
62 63 }
63 64
64 65 public MaterialChoice(@NotNull List<Material> choices) {
65 66 Preconditions.checkArgument(choices != null, "choices");
66 67 Preconditions.checkArgument(!choices.isEmpty(), "Must have at least one choice");
67 68 for (Material choice : choices) {
68 69 Preconditions.checkArgument(choice != null, "Cannot have null choice");
70 + Preconditions.checkArgument(!choice.isAir(), "Cannot have empty/air choice");
69 71 }
70 72
71 73 this.choices = new ArrayList<>(choices);
72 74 }
73 75
74 76 @Override
75 77 public boolean test(@NotNull ItemStack t) {
76 78 for (Material match : choices) {
77 79 if (t.getType() == match) {
78 80 return true;
159 161
160 162 public ExactChoice(@NotNull ItemStack... stacks) {
161 163 this(Arrays.asList(stacks));
162 164 }
163 165
164 166 public ExactChoice(@NotNull List<ItemStack> choices) {
165 167 Preconditions.checkArgument(choices != null, "choices");
166 168 Preconditions.checkArgument(!choices.isEmpty(), "Must have at least one choice");
167 169 for (ItemStack choice : choices) {
168 170 Preconditions.checkArgument(choice != null, "Cannot have null choice");
171 + Preconditions.checkArgument(!choice.getType().isAir(), "Cannot have empty/air choice");
169 172 }
170 173
171 174 this.choices = new ArrayList<>(choices);
172 175 }
173 176
174 177 @NotNull
175 178 @Override
176 179 public ItemStack getItemStack() {
177 180 return choices.get(0).clone();
178 181 }

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

Add shortcut