Skip to content

Commit

Permalink
Add ItemMeta customName methods (#11685)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv authored Dec 7, 2024
1 parent d4630f1 commit 5403894
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 46 deletions.
147 changes: 131 additions & 16 deletions patches/api/0006-Adventure.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4713,35 +4713,77 @@ index 9bab73c3c2ca759b8e1c7d07d98cc593c961666a..f0c6943da3f783101ca647b75b3230fa
throw new UnsupportedOperationException("Not supported yet.");
}
diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
index 69d6de6e9618dd27f5ba73b931f8455912caf060..77f0e0a9e991f65b89909d0307fd93c3ecd9d8ac 100644
index 69d6de6e9618dd27f5ba73b931f8455912caf060..753a756525f6afea981dd0c2984e7a747d4d148b 100644
--- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
+++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
@@ -45,6 +45,24 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
*/
boolean hasDisplayName();
@@ -38,12 +38,65 @@ import org.jetbrains.annotations.Nullable;
*/
public interface ItemMeta extends Cloneable, ConfigurationSerializable, PersistentDataHolder {

+ // Paper start
+ /**
+ * Checks for existence of a custom name.
+ *
+ * @return true if this has a custom name
+ */
+ boolean hasCustomName();
+
+ /**
+ * Gets the custom name.
+ *
+ * <p>Plugins should check that {@link #hasCustomName()} returns {@code true} before calling this method.</p>
+ *
+ * @return the custom name
+ */
+ net.kyori.adventure.text.@Nullable Component customName();
+
+ /**
+ * Sets the custom name.
+ *
+ * @param customName the custom name to set
+ */
+ void customName(final net.kyori.adventure.text.@Nullable Component customName);
+
/**
* Checks for existence of a display name.
*
+ * @apiNote This method is obsolete, use {@link #hasCustomName()} instead.
* @return true if this has a display name
*/
- boolean hasDisplayName();
+ @ApiStatus.Obsolete(since = "1.21.4")
+ default boolean hasDisplayName() {
+ return this.hasCustomName();
+ }
+
+ /**
+ * Gets the display name.
+ *
+ * <p>Plugins should check that {@link #hasDisplayName()} returns <code>true</code> before calling this method.</p>
+ *
+ * @apiNote This method is obsolete, use {@link #customName()} instead.
+ * @return the display name
+ */
+ net.kyori.adventure.text.@Nullable Component displayName();
+ @ApiStatus.Obsolete(since = "1.21.4")
+ default net.kyori.adventure.text.@Nullable Component displayName() {
+ return this.customName();
+ }
+
+ /**
+ * Sets the display name.
+ *
+ * @param displayName the display name to set
+ * @apiNote This method is obsolete, use {@link #customName(Component)} instead.
+ */
+ void displayName(final net.kyori.adventure.text.@Nullable Component displayName);
+ @ApiStatus.Obsolete(since = "1.21.4")
+ default void displayName(final net.kyori.adventure.text.@Nullable Component displayName) {
+ this.customName(displayName);
+ }
+ // Paper end
+
/**
* Gets the display name that is set.
* <p>
@@ -52,7 +70,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -52,7 +105,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
* before calling this method.
*
* @return the display name that is set
Expand All @@ -4751,7 +4793,7 @@ index 69d6de6e9618dd27f5ba73b931f8455912caf060..77f0e0a9e991f65b89909d0307fd93c3
@NotNull
String getDisplayName();

@@ -60,7 +80,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -60,7 +115,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
* Sets the display name.
*
* @param name the name to set
Expand All @@ -4761,7 +4803,7 @@ index 69d6de6e9618dd27f5ba73b931f8455912caf060..77f0e0a9e991f65b89909d0307fd93c3
void setDisplayName(@Nullable String name);

/**
@@ -73,6 +95,32 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -73,6 +130,32 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
*/
boolean hasItemName();

Expand Down Expand Up @@ -4794,7 +4836,7 @@ index 69d6de6e9618dd27f5ba73b931f8455912caf060..77f0e0a9e991f65b89909d0307fd93c3
/**
* Gets the item name that is set.
* <br>
@@ -83,7 +131,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -83,7 +166,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
* calling this method.
*
* @return the item name that is set
Expand All @@ -4804,7 +4846,7 @@ index 69d6de6e9618dd27f5ba73b931f8455912caf060..77f0e0a9e991f65b89909d0307fd93c3
@NotNull
String getItemName();

@@ -94,7 +144,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -94,7 +179,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
* anvil, is not styled with italics, and does not show labels.
*
* @param name the name to set
Expand All @@ -4814,7 +4856,7 @@ index 69d6de6e9618dd27f5ba73b931f8455912caf060..77f0e0a9e991f65b89909d0307fd93c3
void setItemName(@Nullable String name);

/**
@@ -135,6 +187,24 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -135,6 +222,24 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
*/
boolean hasLore();

Expand All @@ -4839,7 +4881,7 @@ index 69d6de6e9618dd27f5ba73b931f8455912caf060..77f0e0a9e991f65b89909d0307fd93c3
/**
* Gets the lore that is set.
* <p>
@@ -142,7 +212,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -142,7 +247,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
* calling this method.
*
* @return a list of lore that is set
Expand All @@ -4849,7 +4891,7 @@ index 69d6de6e9618dd27f5ba73b931f8455912caf060..77f0e0a9e991f65b89909d0307fd93c3
@Nullable
List<String> getLore();

@@ -151,7 +223,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -151,7 +258,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
* Removes lore when given null.
*
* @param lore the lore that will be set
Expand All @@ -4859,6 +4901,79 @@ index 69d6de6e9618dd27f5ba73b931f8455912caf060..77f0e0a9e991f65b89909d0307fd93c3
void setLore(@Nullable List<String> lore);

/**
diff --git a/src/main/java/org/bukkit/inventory/meta/PotionMeta.java b/src/main/java/org/bukkit/inventory/meta/PotionMeta.java
index b61d2e322f80fcabae5e286cba8df9701ebcf5ea..ada7b3d8f5743fa4dd7809060f1c5a5608b7aec3 100644
--- a/src/main/java/org/bukkit/inventory/meta/PotionMeta.java
+++ b/src/main/java/org/bukkit/inventory/meta/PotionMeta.java
@@ -149,27 +149,64 @@ public interface PotionMeta extends ItemMeta {
/**
* Checks for existence of a custom potion name translation suffix.
*
+ * @deprecated conflicting name, use {@link #hasCustomPotionName()}
* @return true if this has a custom potion name
*/
- boolean hasCustomName();
+ @Deprecated(forRemoval = true, since = "1.21.4")
+ default boolean hasCustomName() {
+ return this.hasCustomPotionName();
+ }

/**
* Gets the potion name translation suffix that is set.
* <p>
- * Plugins should check that hasCustomName() returns <code>true</code>
+ * Plugins should check that {@link #hasCustomPotionName()} returns {@code true}
* before calling this method.
*
+ * @deprecated conflicting name, use {@link #getCustomPotionName()}
* @return the potion name that is set
*/
+ @Deprecated(forRemoval = true, since = "1.21.4")
@Nullable
- String getCustomName();
+ default String getCustomName() {
+ return this.getCustomPotionName();
+ }

/**
* Sets the potion name translation suffix.
*
+ * @deprecated conflicting name, use {@link #setCustomPotionName(String)}
* @param name the name to set
*/
- void setCustomName(@Nullable String name);
+ @Deprecated(forRemoval = true, since = "1.21.4")
+ default void setCustomName(@Nullable String name) {
+ this.setCustomPotionName(name);
+ }
+
+ /**
+ * Checks for existence of a custom potion name translation suffix.
+ *
+ * @return true if this has a custom potion name
+ */
+ boolean hasCustomPotionName();
+
+ /**
+ * Gets the potion name translation suffix that is set.
+ * <p>
+ * Plugins should check that {@link #hasCustomPotionName()} returns {@code true}
+ * before calling this method.
+ *
+ * @return the potion name that is set
+ */
+ @Nullable
+ String getCustomPotionName();
+
+ /**
+ * Sets the potion name translation suffix.
+ *
+ * @param name the name to set
+ */
+ void setCustomPotionName(@Nullable String name);

@Override
PotionMeta clone();
diff --git a/src/main/java/org/bukkit/inventory/meta/WritableBookMeta.java b/src/main/java/org/bukkit/inventory/meta/WritableBookMeta.java
index 12595536080ffe09df2b6ecdb83d846f50100d38..9fc47c879ee6b8edf2503f20e4736c2997d2de2e 100644
--- a/src/main/java/org/bukkit/inventory/meta/WritableBookMeta.java
Expand Down
12 changes: 6 additions & 6 deletions patches/api/0053-Fix-upstream-javadocs.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1622,10 +1622,10 @@ index 35c6594fd1040a1af1029e7260e5e3a9307b107d..d58719ee75bef8bc265bfc81bc5d88a4
void addChargedProjectile(@NotNull ItemStack item);
}
diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
index 77f0e0a9e991f65b89909d0307fd93c3ecd9d8ac..66315ae78d6143ac6bde2b3a2b40b617dc4b1aab 100644
index 753a756525f6afea981dd0c2984e7a747d4d148b..c083ac4344dd1b2b56cbe103ce80daac945defd5 100644
--- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
+++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
@@ -293,7 +293,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -328,7 +328,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
/**
* Gets the enchantable component. Higher values allow higher enchantments.
*
Expand All @@ -1634,7 +1634,7 @@ index 77f0e0a9e991f65b89909d0307fd93c3ecd9d8ac..66315ae78d6143ac6bde2b3a2b40b617
*/
int getEnchantable();

@@ -626,11 +626,6 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -661,11 +661,6 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste

/**
* Gets the item which this item will convert to when used.
Expand All @@ -1646,7 +1646,7 @@ index 77f0e0a9e991f65b89909d0307fd93c3ecd9d8ac..66315ae78d6143ac6bde2b3a2b40b617
*
* @return remainder
*/
@@ -767,7 +762,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -802,7 +797,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
* The returned component is a snapshot of its current state and does not
* reflect a live view of what is on an item. After changing any value on
* this component, it must be set with
Expand All @@ -1655,7 +1655,7 @@ index 77f0e0a9e991f65b89909d0307fd93c3ecd9d8ac..66315ae78d6143ac6bde2b3a2b40b617
* to apply the changes.
*
* @return component
@@ -776,7 +771,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -811,7 +806,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
JukeboxPlayableComponent getJukeboxPlayable();

/**
Expand All @@ -1664,7 +1664,7 @@ index 77f0e0a9e991f65b89909d0307fd93c3ecd9d8ac..66315ae78d6143ac6bde2b3a2b40b617
*
* @param jukeboxPlayable new component
*/
@@ -803,7 +798,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -838,7 +833,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
/**
* Return an immutable copy of all {@link Attribute}s and their
* {@link AttributeModifier}s for a given {@link EquipmentSlot}.<br>
Expand Down
10 changes: 5 additions & 5 deletions patches/api/0166-Fix-Spigot-annotation-mistakes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1748,34 +1748,34 @@ index 597a18a767b68b47e81454b7d44613c7178c1366..bc3440eb72127824b3961fbdae583bb6
public ItemStack getInput() {
return this.ingredient.getItemStack();
diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
index 66315ae78d6143ac6bde2b3a2b40b617dc4b1aab..b770541429649cefed3f7f907cc1d9653e395937 100644
index c083ac4344dd1b2b56cbe103ce80daac945defd5..4012a1b4e9acdfafb38c78a54c4b422ffa07cf04 100644
--- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
+++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
@@ -152,6 +152,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -187,6 +187,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
/**
* Checks for existence of a localized name.
*
+ * @deprecated Use {@link ItemMeta#displayName()} and check if it is instanceof a {@link net.kyori.adventure.text.TranslatableComponent}.
* @return true if this has a localized name
* @deprecated meta no longer exists
*/
@@ -164,6 +165,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -199,6 +200,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
* Plugins should check that hasLocalizedName() returns <code>true</code>
* before calling this method.
*
+ * @deprecated Use {@link ItemMeta#displayName()} and cast it to a {@link net.kyori.adventure.text.TranslatableComponent}. No longer used by the client.
* @return the localized name that is set
* @deprecated meta no longer exists
*/
@@ -174,6 +176,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -209,6 +211,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
/**
* Sets the localized name.
*
+ * @deprecated Use {@link ItemMeta#displayName(Component)} with a {@link net.kyori.adventure.text.TranslatableComponent}. No longer used by the client.
* @param name the name to set
* @deprecated meta no longer exists
*/
@@ -767,7 +770,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -802,7 +805,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
*
* @return component
*/
Expand Down
10 changes: 5 additions & 5 deletions patches/api/0193-Support-components-in-ItemMeta.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Support components in ItemMeta


diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
index eb14949da2b96aee75e3bba63af8176c5550a380..0151a0523069b00a1cf682ad6b54142aaffcfaa6 100644
index 4012a1b4e9acdfafb38c78a54c4b422ffa07cf04..cca91212e702a73e9fc37ec46d575967fedf68c9 100644
--- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
+++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
@@ -5,6 +5,7 @@ import java.util.Collection;
Expand All @@ -16,7 +16,7 @@ index eb14949da2b96aee75e3bba63af8176c5550a380..0151a0523069b00a1cf682ad6b54142a
import org.bukkit.NamespacedKey;
import org.bukkit.Tag;
import org.bukkit.attribute.Attribute;
@@ -76,6 +77,20 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -111,6 +112,20 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@NotNull
String getDisplayName();

Expand All @@ -37,7 +37,7 @@ index eb14949da2b96aee75e3bba63af8176c5550a380..0151a0523069b00a1cf682ad6b54142a
/**
* Sets the display name.
*
@@ -85,6 +100,16 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -120,6 +135,16 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@Deprecated // Paper
void setDisplayName(@Nullable String name);

Expand All @@ -54,7 +54,7 @@ index eb14949da2b96aee75e3bba63af8176c5550a380..0151a0523069b00a1cf682ad6b54142a
/**
* Checks for existence of an item name.
* <br>
@@ -221,6 +246,19 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -256,6 +281,19 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@Nullable
List<String> getLore();

Expand All @@ -74,7 +74,7 @@ index eb14949da2b96aee75e3bba63af8176c5550a380..0151a0523069b00a1cf682ad6b54142a
/**
* Sets the lore for this item.
* Removes lore when given null.
@@ -231,6 +269,16 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -266,6 +304,16 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@Deprecated // Paper
void setLore(@Nullable List<String> lore);

Expand Down
6 changes: 3 additions & 3 deletions patches/api/0468-General-ItemMeta-fixes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ index ff6818b6d9e0207eafdd749928f33aeac3f27191..992f39da07bafe9769effaa7dc6adc01
* Checks to see if this item has a maximum amount of damage.
*
diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
index e95eac71ab43cadccf99ff594cc77a6d364c46bd..f32102441df03645c1b8c80fdfc944018e5544ca 100644
index cca91212e702a73e9fc37ec46d575967fedf68c9..2035d54de7e446930f8fdd2a572240e70a21c656 100644
--- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
+++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
@@ -351,7 +351,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -386,7 +386,7 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
/**
* Sets the enchantable. Higher values allow higher enchantments.
*
Expand All @@ -124,7 +124,7 @@ index e95eac71ab43cadccf99ff594cc77a6d364c46bd..f32102441df03645c1b8c80fdfc94401
*/
void setEnchantable(@Nullable Integer enchantable);

@@ -895,8 +895,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -930,8 +930,9 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste

/**
* Set all {@link Attribute}s and their {@link AttributeModifier}s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ index 6d266c111bfa2bd51338e03ed740f6ac81ed07c7..d71531c384c57ea44d1e1fbe394214c1
return key;
}
diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
index f32102441df03645c1b8c80fdfc944018e5544ca..403c4e7138bcee1321b16fb3aa4cffb2178d4757 100644
index 2035d54de7e446930f8fdd2a572240e70a21c656..e8c0b8848abce2c9e8b2be880de3897292f0b23e 100644
--- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
+++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
@@ -1028,4 +1028,98 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@@ -1063,4 +1063,98 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
@SuppressWarnings("javadoc")
@NotNull
ItemMeta clone();
Expand Down
Loading

0 comments on commit 5403894

Please sign in to comment.