Fix NPE for AIR in meta operations in ItemStack
This commit is contained in:
parent
2e70796c7f
commit
d7795080c7
1 changed files with 15 additions and 3 deletions
|
@ -5,7 +5,7 @@ Subject: [PATCH] ItemStack API additions for quantity/flags/lore
|
||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
|
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
|
||||||
index cc065602db56c51b87d273a52d9ef82439fcaa7a..41db4fdbf25d7a2a7b6db373cf2eecc8cd9a5aa7 100644
|
index cc065602db56c51b87d273a52d9ef82439fcaa7a..db701a709d5fa2d5a6a96846e0ce2342350fb897 100644
|
||||||
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
|
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
|
||||||
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
|
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
|
||||||
@@ -2,7 +2,9 @@ package org.bukkit.inventory;
|
@@ -2,7 +2,9 @@ package org.bukkit.inventory;
|
||||||
|
@ -18,7 +18,7 @@ index cc065602db56c51b87d273a52d9ef82439fcaa7a..41db4fdbf25d7a2a7b6db373cf2eecc8
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -635,5 +637,140 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor
|
@@ -635,5 +637,152 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor
|
||||||
// Requires access to NMS
|
// Requires access to NMS
|
||||||
return ensureServerConversions().getMaxItemUseDuration();
|
return ensureServerConversions().getMaxItemUseDuration();
|
||||||
}
|
}
|
||||||
|
@ -110,6 +110,9 @@ index cc065602db56c51b87d273a52d9ef82439fcaa7a..41db4fdbf25d7a2a7b6db373cf2eecc8
|
||||||
+ */
|
+ */
|
||||||
+ public void setLore(@Nullable List<String> lore) {
|
+ public void setLore(@Nullable List<String> lore) {
|
||||||
+ ItemMeta itemMeta = getItemMeta();
|
+ ItemMeta itemMeta = getItemMeta();
|
||||||
|
+ if (itemMeta == null) {
|
||||||
|
+ throw new IllegalStateException("Cannot set lore on " + getType());
|
||||||
|
+ }
|
||||||
+ itemMeta.setLore(lore);
|
+ itemMeta.setLore(lore);
|
||||||
+ setItemMeta(itemMeta);
|
+ setItemMeta(itemMeta);
|
||||||
+ }
|
+ }
|
||||||
|
@ -121,6 +124,9 @@ index cc065602db56c51b87d273a52d9ef82439fcaa7a..41db4fdbf25d7a2a7b6db373cf2eecc8
|
||||||
+ */
|
+ */
|
||||||
+ public void addItemFlags(@NotNull ItemFlag... itemFlags) {
|
+ public void addItemFlags(@NotNull ItemFlag... itemFlags) {
|
||||||
+ ItemMeta itemMeta = getItemMeta();
|
+ ItemMeta itemMeta = getItemMeta();
|
||||||
|
+ if (itemMeta == null) {
|
||||||
|
+ throw new IllegalStateException("Cannot add flags on " + getType());
|
||||||
|
+ }
|
||||||
+ itemMeta.addItemFlags(itemFlags);
|
+ itemMeta.addItemFlags(itemFlags);
|
||||||
+ setItemMeta(itemMeta);
|
+ setItemMeta(itemMeta);
|
||||||
+ }
|
+ }
|
||||||
|
@ -132,6 +138,9 @@ index cc065602db56c51b87d273a52d9ef82439fcaa7a..41db4fdbf25d7a2a7b6db373cf2eecc8
|
||||||
+ */
|
+ */
|
||||||
+ public void removeItemFlags(@NotNull ItemFlag... itemFlags) {
|
+ public void removeItemFlags(@NotNull ItemFlag... itemFlags) {
|
||||||
+ ItemMeta itemMeta = getItemMeta();
|
+ ItemMeta itemMeta = getItemMeta();
|
||||||
|
+ if (itemMeta == null) {
|
||||||
|
+ throw new IllegalStateException("Cannot remove flags on " + getType());
|
||||||
|
+ }
|
||||||
+ itemMeta.removeItemFlags(itemFlags);
|
+ itemMeta.removeItemFlags(itemFlags);
|
||||||
+ setItemMeta(itemMeta);
|
+ setItemMeta(itemMeta);
|
||||||
+ }
|
+ }
|
||||||
|
@ -144,6 +153,9 @@ index cc065602db56c51b87d273a52d9ef82439fcaa7a..41db4fdbf25d7a2a7b6db373cf2eecc8
|
||||||
+ @NotNull
|
+ @NotNull
|
||||||
+ public Set<ItemFlag> getItemFlags() {
|
+ public Set<ItemFlag> getItemFlags() {
|
||||||
+ ItemMeta itemMeta = getItemMeta();
|
+ ItemMeta itemMeta = getItemMeta();
|
||||||
|
+ if (itemMeta == null) {
|
||||||
|
+ return java.util.Collections.emptySet();
|
||||||
|
+ }
|
||||||
+ return itemMeta.getItemFlags();
|
+ return itemMeta.getItemFlags();
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
@ -155,7 +167,7 @@ index cc065602db56c51b87d273a52d9ef82439fcaa7a..41db4fdbf25d7a2a7b6db373cf2eecc8
|
||||||
+ */
|
+ */
|
||||||
+ public boolean hasItemFlag(@NotNull ItemFlag flag) {
|
+ public boolean hasItemFlag(@NotNull ItemFlag flag) {
|
||||||
+ ItemMeta itemMeta = getItemMeta();
|
+ ItemMeta itemMeta = getItemMeta();
|
||||||
+ return itemMeta.hasItemFlag(flag);
|
+ return itemMeta != null && itemMeta.hasItemFlag(flag);
|
||||||
+ }
|
+ }
|
||||||
// Paper end
|
// Paper end
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue