mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-14 05:33:56 +01:00
Add ItemMeta customName methods (#11685)
This commit is contained in:
parent
41f4119eb0
commit
04df9cac25
4 changed files with 208 additions and 12 deletions
|
@ -4716,31 +4716,73 @@ diff --git a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java b/src/main/ja
|
|||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
|
||||
+++ b/src/main/java/org/bukkit/inventory/meta/ItemMeta.java
|
||||
@@ -0,0 +0,0 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
|
||||
*/
|
||||
boolean hasDisplayName();
|
||||
@@ -0,0 +0,0 @@ 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>
|
||||
@@ -0,0 +0,0 @@ public interface ItemMeta extends Cloneable, ConfigurationSerializable, Persiste
|
||||
* before calling this method.
|
||||
*
|
||||
|
@ -4859,6 +4901,79 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/inventory/meta/PotionMeta.java
|
||||
+++ b/src/main/java/org/bukkit/inventory/meta/PotionMeta.java
|
||||
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/inventory/meta/WritableBookMeta.java
|
||||
|
|
|
@ -5237,19 +5237,28 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
|
||||
+ // Paper start
|
||||
+ @Override
|
||||
+ public net.kyori.adventure.text.Component displayName() {
|
||||
+ public net.kyori.adventure.text.Component customName() {
|
||||
+ return displayName == null ? null : io.papermc.paper.adventure.PaperAdventure.asAdventure(displayName);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void displayName(final net.kyori.adventure.text.Component displayName) {
|
||||
+ this.displayName = displayName == null ? null : io.papermc.paper.adventure.PaperAdventure.asVanilla(displayName);
|
||||
+ public void customName(final net.kyori.adventure.text.Component customName) {
|
||||
+ this.displayName = customName == null ? null : io.papermc.paper.adventure.PaperAdventure.asVanilla(customName);
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return CraftChatMessage.fromComponent(this.displayName);
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
}
|
||||
|
||||
@Override
|
||||
- public boolean hasDisplayName() {
|
||||
+ public boolean hasCustomName() {
|
||||
return this.displayName != null;
|
||||
}
|
||||
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
return this.itemName != null;
|
||||
}
|
||||
|
@ -5288,6 +5297,78 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
@Override
|
||||
public boolean hasRepairCost() {
|
||||
return this.repairCost > 0;
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java
|
||||
@@ -0,0 +0,0 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
|
||||
String name = SerializableMeta.getString(map, CraftMetaPotion.CUSTOM_NAME.BUKKIT, true);
|
||||
if (name != null) {
|
||||
- this.setCustomName(name);
|
||||
+ this.setCustomPotionName(name);
|
||||
}
|
||||
|
||||
Iterable<?> rawEffectList = SerializableMeta.getObject(Iterable.class, map, CraftMetaPotion.POTION_EFFECTS.BUKKIT, true);
|
||||
@@ -0,0 +0,0 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
}
|
||||
|
||||
boolean isPotionEmpty() {
|
||||
- return (this.type == null) && !(this.hasCustomEffects() || this.hasColor() || this.hasCustomName());
|
||||
+ return (this.type == null) && !(this.hasCustomEffects() || this.hasColor() || this.hasCustomPotionName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +0,0 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
}
|
||||
|
||||
@Override
|
||||
- public boolean hasCustomName() {
|
||||
+ public boolean hasCustomPotionName() {
|
||||
return this.customName != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
- public String getCustomName() {
|
||||
+ public String getCustomPotionName() {
|
||||
return this.customName;
|
||||
}
|
||||
|
||||
@Override
|
||||
- public void setCustomName(String customName) {
|
||||
+ public void setCustomPotionName(String customName) {
|
||||
this.customName = customName;
|
||||
}
|
||||
|
||||
@@ -0,0 +0,0 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
if (this.hasColor()) {
|
||||
hash = 73 * hash + this.color.hashCode();
|
||||
}
|
||||
- if (this.hasCustomName()) {
|
||||
+ if (this.hasCustomPotionName()) {
|
||||
hash = 73 * hash + this.customName.hashCode();
|
||||
}
|
||||
if (this.hasCustomEffects()) {
|
||||
@@ -0,0 +0,0 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
return Objects.equals(this.type, that.type)
|
||||
&& (this.hasCustomEffects() ? that.hasCustomEffects() && this.customEffects.equals(that.customEffects) : !that.hasCustomEffects())
|
||||
&& (this.hasColor() ? that.hasColor() && this.color.equals(that.color) : !that.hasColor())
|
||||
- && (this.hasCustomName() ? that.hasCustomName() && this.customName.equals(that.customName) : !that.hasCustomName());
|
||||
+ && (this.hasCustomPotionName() ? that.hasCustomPotionName() && this.customName.equals(that.customName) : !that.hasCustomPotionName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +0,0 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
builder.put(CraftMetaPotion.POTION_COLOR.BUKKIT, this.getColor());
|
||||
}
|
||||
|
||||
- if (this.hasCustomName()) {
|
||||
- builder.put(CraftMetaPotion.CUSTOM_NAME.BUKKIT, this.getCustomName());
|
||||
+ if (this.hasCustomPotionName()) {
|
||||
+ builder.put(CraftMetaPotion.CUSTOM_NAME.BUKKIT, this.getCustomPotionName());
|
||||
}
|
||||
|
||||
if (this.hasCustomEffects()) {
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java b/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/trim/CraftTrimMaterial.java
|
||||
|
|
|
@ -1653,7 +1653,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
@@ -0,0 +0,0 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta {
|
||||
|
||||
@Override
|
||||
public void setCustomName(String customName) {
|
||||
public void setCustomPotionName(String customName) {
|
||||
+ Preconditions.checkArgument(customName == null || customName.length() <= 32767, "Custom name is longer than 32767 characters");
|
||||
this.customName = customName;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ }
|
||||
+ // Paper end
|
||||
@Override
|
||||
public boolean hasDisplayName() {
|
||||
public boolean hasCustomName() {
|
||||
return this.displayName != null;
|
||||
@@ -0,0 +0,0 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||
return this.lore == null ? null : new ArrayList<String>(Lists.transform(this.lore, CraftChatMessage::fromComponent));
|
||||
|
|
Loading…
Reference in a new issue