13
0
geforkt von Mirrors/Paper

SPIGOT-5515: Add basic validation against creating non-item itemstacks

By: md_5 <git@md-5.net>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2020-01-15 14:03:12 +11:00
Ursprung b8b594d610
Commit e5ce128c45

Datei anzeigen

@ -68,6 +68,7 @@ public class ItemStack implements Cloneable, ConfigurationSerializable {
@Deprecated @Deprecated
public ItemStack(@NotNull final Material type, final int amount, final short damage, @Nullable final Byte data) { public ItemStack(@NotNull final Material type, final int amount, final short damage, @Nullable final Byte data) {
Validate.notNull(type, "Material cannot be null"); Validate.notNull(type, "Material cannot be null");
Validate.isTrue(type.isItem(), "Material must be an item: ", type);
this.type = type; this.type = type;
this.amount = amount; this.amount = amount;
if (damage != 0) { if (damage != 0) {
@ -116,6 +117,7 @@ public class ItemStack implements Cloneable, ConfigurationSerializable {
@Utility @Utility
public void setType(@NotNull Material type) { public void setType(@NotNull Material type) {
Validate.notNull(type, "Material cannot be null"); Validate.notNull(type, "Material cannot be null");
Validate.isTrue(type.isItem(), "Material must be an item: ", type);
this.type = type; this.type = type;
if (this.meta != null) { if (this.meta != null) {
this.meta = Bukkit.getItemFactory().asMetaFor(meta, type); this.meta = Bukkit.getItemFactory().asMetaFor(meta, type);