Deprecate ItemStack#setLore(List<String>) and ItemStack#getLore, add Component based alternatives

This commit is contained in:
jmp 2021-03-18 22:04:54 -07:00 committed by Mariell Hoversholm
parent 9889c651ce
commit 087aa70e7c

View File

@ -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..db701a709d5fa2d5a6a96846e0ce2342350fb897 100644 index cc065602db56c51b87d273a52d9ef82439fcaa7a..c6eca5a69cb8f5b161ff99ecad9475be64dcfed5 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..db701a709d5fa2d5a6a96846e0ce2342
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,152 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor @@ -635,5 +637,185 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor
// Requires access to NMS // Requires access to NMS
return ensureServerConversions().getMaxItemUseDuration(); return ensureServerConversions().getMaxItemUseDuration();
} }
@ -89,9 +89,10 @@ index cc065602db56c51b87d273a52d9ef82439fcaa7a..db701a709d5fa2d5a6a96846e0ce2342
+ /** + /**
+ * If the item has lore, returns it, else it will return null + * If the item has lore, returns it, else it will return null
+ * @return The lore, or null + * @return The lore, or null
+ * @deprecated in favor of {@link #lore()}
+ */ + */
+ @Nullable + @Deprecated
+ public List<String> getLore() { + public @Nullable List<String> getLore() {
+ if (!hasItemMeta()) { + if (!hasItemMeta()) {
+ return null; + return null;
+ } + }
@ -103,11 +104,28 @@ index cc065602db56c51b87d273a52d9ef82439fcaa7a..db701a709d5fa2d5a6a96846e0ce2342
+ } + }
+ +
+ /** + /**
+ * If the item has lore, returns it, else it will return null
+ * @return The lore, or null
+ */
+ public @Nullable List<net.kyori.adventure.text.Component> lore() {
+ if (!this.hasItemMeta()) {
+ return null;
+ }
+ final ItemMeta itemMeta = getItemMeta();
+ if (!itemMeta.hasLore()) {
+ return null;
+ }
+ return itemMeta.lore();
+ }
+
+ /**
+ * Sets the lore for this item. + * Sets the lore for this item.
+ * Removes lore when given null. + * Removes lore when given null.
+ * + *
+ * @param lore the lore that will be set + * @param lore the lore that will be set
+ * @deprecated in favour of {@link #lore(List)}
+ */ + */
+ @Deprecated
+ public void setLore(@Nullable List<String> lore) { + public void setLore(@Nullable List<String> lore) {
+ ItemMeta itemMeta = getItemMeta(); + ItemMeta itemMeta = getItemMeta();
+ if (itemMeta == null) { + if (itemMeta == null) {
@ -118,6 +136,21 @@ index cc065602db56c51b87d273a52d9ef82439fcaa7a..db701a709d5fa2d5a6a96846e0ce2342
+ } + }
+ +
+ /** + /**
+ * Sets the lore for this item.
+ * Removes lore when given null.
+ *
+ * @param lore the lore that will be set
+ */
+ public void lore(@Nullable List<net.kyori.adventure.text.Component> lore) {
+ ItemMeta itemMeta = getItemMeta();
+ if (itemMeta == null) {
+ throw new IllegalStateException("Cannot set lore on " + getType());
+ }
+ itemMeta.lore(lore);
+ this.setItemMeta(itemMeta);
+ }
+
+ /**
+ * Set itemflags which should be ignored when rendering a ItemStack in the Client. This Method does silently ignore double set itemFlags. + * Set itemflags which should be ignored when rendering a ItemStack in the Client. This Method does silently ignore double set itemFlags.
+ * + *
+ * @param itemFlags The hideflags which shouldn't be rendered + * @param itemFlags The hideflags which shouldn't be rendered