diff --git a/patches/api/0495-Add-ItemStack-effectiveName.patch b/patches/api/0495-Add-ItemStack-effectiveName.patch new file mode 100644 index 000000000000..92de9bc4645c --- /dev/null +++ b/patches/api/0495-Add-ItemStack-effectiveName.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: masmc05 +Date: Sat, 5 Oct 2024 04:23:14 +0300 +Subject: [PATCH] Add ItemStack#effectiveName + + +diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java +index b59222b8c262545d100a9fd28b3bf1d2a4cf4eb0..7cf153d31c85fa852e90011392d1e09034bbee34 100644 +--- a/src/main/java/org/bukkit/inventory/ItemStack.java ++++ b/src/main/java/org/bukkit/inventory/ItemStack.java +@@ -710,6 +710,17 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat + return Bukkit.getServer().getItemFactory().displayName(this); + } + ++ /** ++ * Gets the effective name of this item stack shown to player in inventory. ++ * It takes into account the display name (with italics) from the item meta, ++ * the potion effect, translatable name, rarity etc. ++ * ++ * @return the effective name of this item stack ++ */ ++ public net.kyori.adventure.text.@NotNull Component effectiveName() { ++ return this.craftDelegate.effectiveName(); ++ } ++ + /** + * Minecraft updates are converting simple item stacks into more complex NBT oriented Item Stacks. + * diff --git a/patches/server/1065-Add-ItemStack-effectiveName.patch b/patches/server/1065-Add-ItemStack-effectiveName.patch new file mode 100644 index 000000000000..d003da1f017a --- /dev/null +++ b/patches/server/1065-Add-ItemStack-effectiveName.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: masmc05 +Date: Sat, 5 Oct 2024 04:23:13 +0300 +Subject: [PATCH] Add ItemStack#effectiveName + + +diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +index f84e07fa0876bb6da0f99f4de6cb811f897adca2..c6a24aca51a612a02f677f2870b5afcfb7b2d47e 100644 +--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java ++++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +@@ -438,6 +438,23 @@ public final class CraftItemStack extends ItemStack { + return true; + } + ++ // Paper start - add ItemStack#effectiveName ++ @Override ++ public net.kyori.adventure.text.Component effectiveName() { ++ // 1.21.2: return this.handle == null ? net.kyori.adventure.text.Component.empty() : io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.getStyledHoverName()); ++ if (this.handle == null) { ++ return net.kyori.adventure.text.Component.empty(); ++ } ++ net.kyori.adventure.text.Component hover = io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.getHoverName()); ++ net.kyori.adventure.text.format.Style.Builder style = hover.style().toBuilder(); ++ style.color(io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.getRarity().color())); ++ if (this.handle.has(DataComponents.CUSTOM_NAME)) { ++ style.decoration(net.kyori.adventure.text.format.TextDecoration.ITALIC, true); ++ } ++ return hover.style(style); ++ } ++ // Paper end - add ItemStack#effectiveName ++ + @Override + public boolean isSimilar(ItemStack stack) { + if (stack == null) {