From f4303373e1cb8d3e9febde18ae4bf626f5f6c2ea Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Sun, 28 Apr 2024 18:08:59 +0100 Subject: [PATCH] Add itemName components (Resolves #10467) (#10471) * Add itemName components (Resolves ##10467) * improve javadocs and formatting * rebased --------- Co-authored-by: Jake Potrebic --- patches/api/Adventure.patch | 53 ++++++++++++++++++++++++++++++++++ patches/server/Adventure.patch | 19 ++++++++++++ 2 files changed, 72 insertions(+) diff --git a/patches/api/Adventure.patch b/patches/api/Adventure.patch index fb055a2cae..da4e6dbf0d 100644 --- a/patches/api/Adventure.patch +++ b/patches/api/Adventure.patch @@ -4643,6 +4643,59 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + @Deprecated // Paper void setDisplayName(@Nullable String name); + /** +@@ -0,0 +0,0 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste + */ + boolean hasItemName(); + ++ // Paper start ++ /** ++ * Gets the item name component that is set. ++ *
++ * Item name differs from display name in that it is cannot be edited by an ++ * anvil, is not styled with italics, and does not show labels. ++ *

++ * Plugins should check that {@link #hasItemName()} returns true before ++ * calling this method. ++ * ++ * @return the item name that is set ++ * @see #hasItemName() ++ */ ++ @org.jetbrains.annotations.NotNull ++ Component itemName(); ++ ++ /** ++ * Sets the item name. ++ *
++ * Item name differs from display name in that it is cannot be edited by an ++ * anvil, is not styled with italics, and does not show labels. ++ * ++ * @param name the name to set, null to remove it ++ */ ++ void itemName(@Nullable final Component name); ++ // Paper end + /** + * Gets the item name that is set. + *
+@@ -0,0 +0,0 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste + * calling this method. + * + * @return the item name that is set ++ * @deprecated in favour of {@link #itemName()} + */ ++ @Deprecated // Paper + @NotNull + String getItemName(); + +@@ -0,0 +0,0 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste + * anvil, is not styled with italics, and does not show labels. + * + * @param name the name to set ++ * @deprecated in favour of {@link #itemName(Component)} + */ ++ @Deprecated // Paper + void setItemName(@Nullable String name); + /** @@ -0,0 +0,0 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste */ diff --git a/patches/server/Adventure.patch b/patches/server/Adventure.patch index 3b8b766ba9..6227c76395 100644 --- a/patches/server/Adventure.patch +++ b/patches/server/Adventure.patch @@ -5163,6 +5163,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @Override public String getDisplayName() { return CraftChatMessage.fromComponent(this.displayName); +@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { + return this.itemName != null; + } + ++ // Paper start - Adventure ++ @Override ++ public net.kyori.adventure.text.Component itemName() { ++ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.itemName); ++ } ++ ++ @Override ++ public void itemName(final net.kyori.adventure.text.Component name) { ++ this.itemName = io.papermc.paper.adventure.PaperAdventure.asVanilla(name); ++ } ++ // Paper end - Adventure ++ + @Override + public String getLocalizedName() { + return this.getDisplayName(); @@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { return this.lore != null && !this.lore.isEmpty(); }