diff options
author | Jake Potrebic <[email protected]> | 2024-04-25 17:46:17 -0700 |
---|---|---|
committer | Jake Potrebic <[email protected]> | 2024-04-25 17:46:17 -0700 |
commit | 10e6143499da91dbcee7c0c89e9e7e8593209a2f (patch) | |
tree | d999d7740b6bc99be72ee448d183e7be301a2289 /patches/server/0010-Adventure.patch | |
parent | e85e1ec4a676f8b8edde0e4a51ebab92e56d0a7d (diff) | |
download | Paper-10e6143499da91dbcee7c0c89e9e7e8593209a2f.tar.gz Paper-10e6143499da91dbcee7c0c89e9e7e8593209a2f.zip |
fixup adventure's book meta handling
Diffstat (limited to 'patches/server/0010-Adventure.patch')
-rw-r--r-- | patches/server/0010-Adventure.patch | 152 |
1 files changed, 111 insertions, 41 deletions
diff --git a/patches/server/0010-Adventure.patch b/patches/server/0010-Adventure.patch index bd24346fbd..a9cff2ccf8 100644 --- a/patches/server/0010-Adventure.patch +++ b/patches/server/0010-Adventure.patch @@ -4806,7 +4806,7 @@ index 9e05a8515c5f6f340182e91150fcad8bbf80a22b..adf22ce4f0bcd3bd57dc2030c6c92d3d @Override public CraftMerchant getCraftMerchant() { diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java -index 61ad00c38cfef8a1de61b4597ec1042428feccf4..4c308de19e26b228151dc05606dd6339649e1765 100644 +index 61ad00c38cfef8a1de61b4597ec1042428feccf4..4da38ebb7fdbdb0f8fa422ebcd2e3eec2b2be846 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java @@ -2,8 +2,9 @@ package org.bukkit.craftbukkit.inventory; @@ -4820,64 +4820,59 @@ index 61ad00c38cfef8a1de61b4597ec1042428feccf4..4c308de19e26b228151dc05606dd6339 import java.util.ArrayList; import java.util.Arrays; import java.util.List; -@@ -170,6 +171,148 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta, WritableBo +@@ -170,6 +171,130 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta, WritableBo public void setGeneration(Generation generation) { } + // Paper start + @Override + public net.kyori.adventure.text.Component title() { -+ return this.title == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.deserialize(this.title); ++ return null; + } + + @Override + public org.bukkit.inventory.meta.BookMeta title(net.kyori.adventure.text.Component title) { -+ this.setTitle(title == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(title)); + return this; + } + + @Override + public net.kyori.adventure.text.Component author() { -+ return this.author == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.deserialize(this.author); ++ return null; + } + + @Override + public org.bukkit.inventory.meta.BookMeta author(net.kyori.adventure.text.Component author) { -+ this.setAuthor(author == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(author)); + return this; + } + + @Override + public net.kyori.adventure.text.Component page(final int page) { -+ Preconditions.checkArgument(isValidPage(page), "Invalid page number"); -+ return this instanceof CraftMetaBookSigned ? net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().deserialize(pages.get(page - 1)) : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(pages.get(page - 1)); ++ Preconditions.checkArgument(this.isValidPage(page), "Invalid page number"); ++ 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 (!isValidPage(page)) { -+ throw new IllegalArgumentException("Invalid page number " + page + "/" + pages.size()); ++ if (!this.isValidPage(page)) { ++ throw new IllegalArgumentException("Invalid page number " + page + "/" + this.pages.size()); + } + if (data == null) { + data = net.kyori.adventure.text.Component.empty(); + } -+ pages.set(page - 1, this instanceof CraftMetaBookSigned ? net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().serialize(data) : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(data)); ++ this.pages.set(page - 1, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(data)); + } + + @Override + public List<net.kyori.adventure.text.Component> pages() { + if (this.pages == null) return ImmutableList.of(); -+ if (this instanceof CraftMetaBookSigned) -+ return pages.stream().map(net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson()::deserialize).collect(ImmutableList.toImmutableList()); -+ else -+ return pages.stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::deserialize).collect(ImmutableList.toImmutableList()); ++ return this.pages.stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::deserialize).collect(ImmutableList.toImmutableList()); + } + + @Override + public BookMeta pages(List<net.kyori.adventure.text.Component> pages) { + if (this.pages != null) this.pages.clear(); + for (net.kyori.adventure.text.Component page : pages) { -+ addPages(page); ++ this.addPages(page); + } + return this; + } @@ -4885,7 +4880,7 @@ index 61ad00c38cfef8a1de61b4597ec1042428feccf4..4c308de19e26b228151dc05606dd6339 + @Override + public BookMeta pages(net.kyori.adventure.text.Component... pages) { + if (this.pages != null) this.pages.clear(); -+ addPages(pages); ++ this.addPages(pages); + return this; + } + @@ -4901,34 +4896,25 @@ index 61ad00c38cfef8a1de61b4597ec1042428feccf4..4c308de19e26b228151dc05606dd6339 + page = net.kyori.adventure.text.Component.empty(); + } + -+ this.pages.add(this instanceof CraftMetaBookSigned ? net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().serialize(page) : net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(page)); ++ this.pages.add(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(page)); + } + } + -+ public static final net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.builder() -+ .character(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.SECTION_CHAR) -+ .build(); -+ private CraftMetaBook(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, List<net.kyori.adventure.text.Component> pages) { ++ private CraftMetaBook(List<net.kyori.adventure.text.Component> pages) { + super((org.bukkit.craftbukkit.inventory.CraftMetaItem) org.bukkit.Bukkit.getItemFactory().getItemMeta(org.bukkit.Material.WRITABLE_BOOK)); -+ this.title = title == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(title); -+ this.author = author == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(author); + this.pages = pages.subList(0, Math.min(MAX_PAGES, pages.size())).stream().map(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()::serialize).collect(java.util.stream.Collectors.toList()); + } + + static class CraftMetaBookBuilder implements BookMetaBuilder { -+ private net.kyori.adventure.text.Component title = null; -+ private net.kyori.adventure.text.Component author = null; -+ private final List<net.kyori.adventure.text.Component> pages = new java.util.ArrayList<>(); ++ protected final List<net.kyori.adventure.text.Component> pages = new java.util.ArrayList<>(); + + @Override + public BookMetaBuilder title(net.kyori.adventure.text.Component title) { -+ this.title = title; + return this; + } + + @Override + public BookMetaBuilder author(net.kyori.adventure.text.Component author) { -+ this.author = author; + return this; + } + @@ -4952,11 +4938,7 @@ index 61ad00c38cfef8a1de61b4597ec1042428feccf4..4c308de19e26b228151dc05606dd6339 + + @Override + public BookMeta build() { -+ return this.build(title, author, pages); -+ } -+ -+ protected BookMeta build(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, java.util.List<net.kyori.adventure.text.Component> pages) { -+ return new CraftMetaBook(title, author, pages); ++ return new CraftMetaBook(this.pages); + } + } + @@ -4969,7 +4951,7 @@ index 61ad00c38cfef8a1de61b4597ec1042428feccf4..4c308de19e26b228151dc05606dd6339 @Override public String getPage(final int page) { Preconditions.checkArgument(this.isValidPage(page), "Invalid page number (%s)", page); -@@ -286,7 +429,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta, WritableBo +@@ -286,7 +411,7 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta, WritableBo } @Override @@ -4979,7 +4961,7 @@ index 61ad00c38cfef8a1de61b4597ec1042428feccf4..4c308de19e26b228151dc05606dd6339 if (this.pages != null) { diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java -index 9c57b883783145ad4483481a2c2e7f0f188cd174..3795207a024ddf2e93baa09bcce56a1253eec8ed 100644 +index 9c57b883783145ad4483481a2c2e7f0f188cd174..b653c2c80e8e8524ea6d7625c6a86f8204c50709 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java @@ -2,7 +2,7 @@ package org.bukkit.craftbukkit.inventory; @@ -5000,23 +4982,41 @@ index 9c57b883783145ad4483481a2c2e7f0f188cd174..3795207a024ddf2e93baa09bcce56a12 super.serialize(builder); if (this.hasTitle()) { -@@ -459,4 +459,25 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta { +@@ -459,4 +459,113 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta { return this.spigot; } // Spigot end + + // Paper start - adventure ++ public static final net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.builder() ++ .character(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.SECTION_CHAR) ++ .build(); + private CraftMetaBookSigned(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, java.util.List<net.kyori.adventure.text.Component> pages) { + super((org.bukkit.craftbukkit.inventory.CraftMetaItem) org.bukkit.Bukkit.getItemFactory().getItemMeta(Material.WRITABLE_BOOK)); -+ this.title = title == null ? null : CraftMetaBook.LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(title); -+ this.author = author == null ? null : CraftMetaBook.LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(author); ++ this.title = title == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(title); ++ this.author = author == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(author); + this.pages = io.papermc.paper.adventure.PaperAdventure.asVanilla(pages.subList(0, Math.min(MAX_PAGES, pages.size()))); + } + + static final class CraftMetaBookSignedBuilder extends CraftMetaBook.CraftMetaBookBuilder { ++ private net.kyori.adventure.text.Component title; ++ private net.kyori.adventure.text.Component author; ++ ++ @Override ++ public org.bukkit.inventory.meta.BookMeta.BookMetaBuilder title(final net.kyori.adventure.text.Component title) { ++ this.title = title; ++ return this; ++ } ++ ++ @Override ++ public org.bukkit.inventory.meta.BookMeta.BookMetaBuilder author(final net.kyori.adventure.text.Component author) { ++ this.author = author; ++ return this; ++ } ++ + @Override -+ protected BookMeta build(net.kyori.adventure.text.Component title, net.kyori.adventure.text.Component author, java.util.List<net.kyori.adventure.text.Component> pages) { -+ return new CraftMetaBookSigned(title, author, pages); ++ public org.bukkit.inventory.meta.BookMeta build() { ++ return new CraftMetaBookSigned(this.title, this.author, this.pages); + } + } + @@ -5024,6 +5024,76 @@ index 9c57b883783145ad4483481a2c2e7f0f188cd174..3795207a024ddf2e93baa09bcce56a12 + public BookMetaBuilder toBuilder() { + return new CraftMetaBookSignedBuilder(); + } ++ ++ @Override ++ public net.kyori.adventure.text.Component title() { ++ return this.title == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.deserialize(this.title); ++ } ++ ++ @Override ++ public org.bukkit.inventory.meta.BookMeta title(net.kyori.adventure.text.Component title) { ++ this.setTitle(title == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(title)); ++ return this; ++ } ++ ++ @Override ++ public net.kyori.adventure.text.Component author() { ++ return this.author == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.deserialize(this.author); ++ } ++ ++ @Override ++ public org.bukkit.inventory.meta.BookMeta author(net.kyori.adventure.text.Component author) { ++ this.setAuthor(author == null ? null : LEGACY_DOWNSAMPLING_COMPONENT_SERIALIZER.serialize(author)); ++ return this; ++ } ++ ++ @Override ++ public net.kyori.adventure.text.Component page(final int page) { ++ Preconditions.checkArgument(this.isValidPage(page), "Invalid page number"); ++ 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()); ++ } ++ this.pages.set(page - 1, io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(data)); ++ } ++ ++ @Override ++ public List<net.kyori.adventure.text.Component> pages() { ++ if (this.pages == null) return ImmutableList.of(); ++ return this.pages.stream().map(io.papermc.paper.adventure.PaperAdventure::asAdventure).collect(ImmutableList.toImmutableList()); ++ } ++ ++ @Override ++ public BookMeta pages(List<net.kyori.adventure.text.Component> pages) { ++ if (this.pages != null) this.pages.clear(); ++ for (net.kyori.adventure.text.Component page : pages) { ++ this.addPages(page); ++ } ++ return this; ++ } ++ ++ @Override ++ public BookMeta pages(net.kyori.adventure.text.Component... pages) { ++ if (this.pages != null) this.pages.clear(); ++ this.addPages(pages); ++ return this; ++ } ++ ++ @Override ++ public void addPages(net.kyori.adventure.text.Component... pages) { ++ if (this.pages == null) this.pages = new ArrayList<>(); ++ for (net.kyori.adventure.text.Component page : pages) { ++ if (this.pages.size() >= MAX_PAGES) { ++ return; ++ } ++ ++ this.pages.add(io.papermc.paper.adventure.PaperAdventure.asVanillaNullToEmpty(page)); ++ } ++ } + // Paper end } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java |