Add itemName components (Resolves #10467) (#10471)

* Add itemName components (Resolves ##10467)

* improve javadocs and formatting

* rebased

---------

Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
This commit is contained in:
Shane Freeder 2024-04-28 18:08:59 +01:00
parent 819639770e
commit f4303373e1
2 changed files with 72 additions and 0 deletions

View file

@ -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.
+ * <br>
+ * 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.
+ * <p>
+ * Plugins should check that {@link #hasItemName()} returns <code>true</code> before
+ * calling this method.
+ *
+ * @return the item name that is set
+ * @see #hasItemName()
+ */
+ @org.jetbrains.annotations.NotNull
+ Component itemName();
+
+ /**
+ * Sets the item name.
+ * <br>
+ * 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.
* <br>
@@ -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
*/

View file

@ -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();
}