diff --git a/paper-api/src/main/java/org/bukkit/inventory/ItemStack.java b/paper-api/src/main/java/org/bukkit/inventory/ItemStack.java index 8c9654cd19..bfefc5299c 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/ItemStack.java +++ b/paper-api/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/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index 78975412da..738d7bf304 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java @@ -467,6 +467,13 @@ public final class CraftItemStack extends ItemStack { return true; } + // Paper start - add ItemStack#effectiveName + @Override + public net.kyori.adventure.text.Component effectiveName() { + return this.handle == null ? net.kyori.adventure.text.Component.empty() : io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.getStyledHoverName()); + } + // Paper end - add ItemStack#effectiveName + @Override public boolean isSimilar(ItemStack stack) { if (stack == null) {