From 61ad933f4dd65f3e5f66f01e3bed8813b326b803 Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Tue, 23 Jul 2024 10:11:00 +0200 Subject: [PATCH] Fix a couple of ItemMeta related NPEs (#11149) --- patches/server/Adventure.patch | 12 ++++-------- patches/server/General-ItemMeta-fixes.patch | 10 ++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/patches/server/Adventure.patch b/patches/server/Adventure.patch index 083c1983ff..239ffe15ad 100644 --- a/patches/server/Adventure.patch +++ b/patches/server/Adventure.patch @@ -4927,15 +4927,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @Override + public net.kyori.adventure.text.Component page(final int page) { -+ Preconditions.checkArgument(this.isValidPage(page), "Invalid page number"); ++ Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s/%s)", page, this.getPageCount()); + return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(this.pages.get(page - 1)); + } + + @Override + public void page(final int page, net.kyori.adventure.text.Component data) { -+ if (!this.isValidPage(page)) { -+ throw new IllegalArgumentException("Invalid page number " + page + "/" + this.pages.size()); -+ } ++ Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s/%s)", page, this.getPageCount()); + if (data == null) { + data = net.kyori.adventure.text.Component.empty(); + } @@ -5120,15 +5118,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @Override + public net.kyori.adventure.text.Component page(final int page) { -+ Preconditions.checkArgument(this.isValidPage(page), "Invalid page number"); ++ Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s/%s)", page, this.getPageCount()); + return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.pages.get(page - 1)); + } + + @Override + public void page(final int page, net.kyori.adventure.text.Component data) { -+ if (!this.isValidPage(page)) { -+ throw new IllegalArgumentException("Invalid page number " + page + "/" + this.pages.size()); -+ } ++ Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s/%s)", page, this.getPageCount()); + this.pages.set(page - 1, io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(data)); + } + diff --git a/patches/server/General-ItemMeta-fixes.patch b/patches/server/General-ItemMeta-fixes.patch index 79cb8e3839..510a8821f6 100644 --- a/patches/server/General-ItemMeta-fixes.patch +++ b/patches/server/General-ItemMeta-fixes.patch @@ -71,6 +71,16 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java +@@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack { + + @Override + public void removeEnchantments() { ++ if (this.handle != null) { // Paper - fix NPE + this.handle.remove(DataComponents.ENCHANTMENTS); ++ } // Paper + } + + @Override @@ -0,0 +0,0 @@ public final class CraftItemStack extends ItemStack { // Paper end - improve handled tags on type change // Paper start