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

This commit is contained in:
Jason Penilla
2021-03-18 22:04:54 -07:00
parent 8bafc17d67
commit a724816abb

View File

@@ -89,9 +89,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ /** + /**
+ * 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 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ +
+ /** + /**
+ * 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 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ +
+ /** + /**
+ * 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