Add ItemMeta customName methods (#11685)

This commit is contained in:
Nassim Jahnke
2024-12-07 20:05:14 +01:00
parent 41f4119eb0
commit 04df9cac25
4 changed files with 208 additions and 12 deletions

View File

@@ -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