1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2025-02-17 02:34:30 +01:00

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
+ * @return The lore, or null
+ * @deprecated in favor of {@link #lore()}
+ */
+ @Nullable
+ public List<String> getLore() {
+ @Deprecated
+ public @Nullable List<String> getLore() {
+ if (!hasItemMeta()) {
+ 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.
+ * Removes lore when given null.
+ *
+ * @param lore the lore that will be set
+ * @deprecated in favour of {@link #lore(List)}
+ */
+ @Deprecated
+ public void setLore(@Nullable List<String> lore) {
+ ItemMeta itemMeta = getItemMeta();
+ 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.
+ *
+ * @param itemFlags The hideflags which shouldn't be rendered