From 2716a6bbcb274721063c450b7f8a9124073f7410 Mon Sep 17 00:00:00 2001 From: masmc05 Date: Sat, 5 Oct 2024 04:24:42 +0300 Subject: [PATCH 1/2] Add ItemStack#effectiveName --- .../0495-Add-ItemStack-effectiveName.patch | 28 +++++++++++++ .../1065-Add-ItemStack-effectiveName.patch | 42 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 patches/api/0495-Add-ItemStack-effectiveName.patch create mode 100644 patches/server/1065-Add-ItemStack-effectiveName.patch 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..ff410523ef73 --- /dev/null +++ b/patches/server/1065-Add-ItemStack-effectiveName.patch @@ -0,0 +1,42 @@ +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..e2191bc42951760b67e475e50be38c6abb3a77b7 100644 +--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java ++++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +@@ -22,6 +22,7 @@ import org.bukkit.inventory.ItemStack; + import org.bukkit.inventory.meta.ItemMeta; + import org.bukkit.material.MaterialData; + import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.NotNull; + + @DelegateDeserialization(ItemStack.class) + public final class CraftItemStack extends ItemStack { +@@ -438,6 +439,23 @@ public final class CraftItemStack extends ItemStack { + return true; + } + ++ // Paper start - add ItemStack#effectiveName ++ @Override ++ public @NotNull 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) { From da6657ece416f4d42af0254e9e2665b61bc95657 Mon Sep 17 00:00:00 2001 From: masmc05 Date: Sat, 5 Oct 2024 04:30:33 +0300 Subject: [PATCH 2/2] Kill the NotNull annotation --- .../server/1065-Add-ItemStack-effectiveName.patch | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/patches/server/1065-Add-ItemStack-effectiveName.patch b/patches/server/1065-Add-ItemStack-effectiveName.patch index ff410523ef73..d003da1f017a 100644 --- a/patches/server/1065-Add-ItemStack-effectiveName.patch +++ b/patches/server/1065-Add-ItemStack-effectiveName.patch @@ -5,24 +5,16 @@ 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..e2191bc42951760b67e475e50be38c6abb3a77b7 100644 +index f84e07fa0876bb6da0f99f4de6cb811f897adca2..c6a24aca51a612a02f677f2870b5afcfb7b2d47e 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java -@@ -22,6 +22,7 @@ import org.bukkit.inventory.ItemStack; - import org.bukkit.inventory.meta.ItemMeta; - import org.bukkit.material.MaterialData; - import org.jetbrains.annotations.ApiStatus; -+import org.jetbrains.annotations.NotNull; - - @DelegateDeserialization(ItemStack.class) - public final class CraftItemStack extends ItemStack { -@@ -438,6 +439,23 @@ public final class CraftItemStack extends ItemStack { +@@ -438,6 +438,23 @@ public final class CraftItemStack extends ItemStack { return true; } + // Paper start - add ItemStack#effectiveName + @Override -+ public @NotNull net.kyori.adventure.text.Component effectiveName() { ++ 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();