diff --git a/Spigot-API-Patches/Adventure.patch b/Spigot-API-Patches/Adventure.patch index b0f99f418b..9b0727ba69 100644 --- a/Spigot-API-Patches/Adventure.patch +++ b/Spigot-API-Patches/Adventure.patch @@ -399,6 +399,100 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return HANDLERS; + } +} +diff --git a/src/main/java/io/papermc/paper/text/PaperComponents.java b/src/main/java/io/papermc/paper/text/PaperComponents.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/text/PaperComponents.java +@@ -0,0 +0,0 @@ ++package io.papermc.paper.text; ++ ++import net.kyori.adventure.text.Component; ++import net.kyori.adventure.text.flattener.ComponentFlattener; ++import net.kyori.adventure.text.format.NamedTextColor; ++import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; ++import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; ++import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; ++import org.bukkit.Bukkit; ++import org.checkerframework.checker.nullness.qual.NonNull; ++ ++/** ++ * Paper API-specific methods for working with {@link Component}s and related. ++ */ ++public final class PaperComponents { ++ private PaperComponents() { ++ throw new RuntimeException("PaperComponents is not to be instantiated!"); ++ } ++ ++ /** ++ * Return a component flattener that can use game data to resolve extra information about components. ++ * ++ * @return a component flattener ++ */ ++ public static @NonNull ComponentFlattener flattener() { ++ return Bukkit.getUnsafe().componentFlattener(); ++ } ++ ++ /** ++ * Get a serializer for {@link Component}s that will convert components to ++ * a plain-text string. ++ * ++ *

Implementations may provide a serializer capable of processing any ++ * information that requires access to implementation details.

++ * ++ * @return a serializer to plain text ++ */ ++ public static @NonNull PlainComponentSerializer plainSerializer() { ++ return Bukkit.getUnsafe().plainComponentSerializer(); ++ } ++ ++ /** ++ * Get a serializer for {@link Component}s that will convert to and from the ++ * standard JSON serialization format using Gson. ++ * ++ *

Implementations may provide a serializer capable of processing any ++ * information that requires implementation details, such as legacy ++ * (pre-1.16) hover events.

++ * ++ * @return a json component serializer ++ */ ++ public static @NonNull GsonComponentSerializer gsonSerializer() { ++ return Bukkit.getUnsafe().gsonComponentSerializer(); ++ } ++ ++ /** ++ * Get a serializer for {@link Component}s that will convert to and from the ++ * standard JSON serialization format using Gson, downsampling any RGB colors ++ * to their nearest {@link NamedTextColor} counterpart. ++ * ++ *

Implementations may provide a serializer capable of processing any ++ * information that requires implementation details, such as legacy ++ * (pre-1.16) hover events.

++ * ++ * @return a json component serializer ++ */ ++ public static @NonNull GsonComponentSerializer colorDownsamplingGsonSerializer() { ++ return Bukkit.getUnsafe().colorDownsamplingGsonComponentSerializer(); ++ } ++ ++ /** ++ * Get a serializer for {@link Component}s that will convert to and from the ++ * legacy component format used by Bukkit. This serializer uses the ++ * {@link LegacyComponentSerializer.Builder#useUnusualXRepeatedCharacterHexFormat()} ++ * option to match upstream behavior. ++ * ++ *

This legacy serializer uses the standard section symbol to mark ++ * formatting characters.

++ * ++ *

Implementations may provide a serializer capable of processing any ++ * information that requires access to implementation details.

++ * ++ * @return a section serializer ++ */ ++ public static @NonNull LegacyComponentSerializer legacySectionSerializer() { ++ return Bukkit.getUnsafe().legacyComponentSerializer(); ++ } ++} diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/Bukkit.java @@ -914,7 +1008,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 */ @Deprecated public interface UnsafeValues { -+ net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer legacyComponentSerializer(); // Paper ++ // Paper start ++ net.kyori.adventure.text.flattener.ComponentFlattener componentFlattener(); ++ net.kyori.adventure.text.serializer.plain.PlainComponentSerializer plainComponentSerializer(); ++ net.kyori.adventure.text.serializer.gson.GsonComponentSerializer gsonComponentSerializer(); ++ net.kyori.adventure.text.serializer.gson.GsonComponentSerializer colorDownsamplingGsonComponentSerializer(); ++ net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer legacyComponentSerializer(); ++ // Paper end void reportTimings(); // Paper Material toLegacy(Material material); diff --git a/Spigot-Server-Patches/Adventure.patch b/Spigot-Server-Patches/Adventure.patch index ac099dcfb0..3a891df8c6 100644 --- a/Spigot-Server-Patches/Adventure.patch +++ b/Spigot-Server-Patches/Adventure.patch @@ -536,9 +536,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + .build(); + public static final LegacyComponentSerializer LEGACY_SECTION_UXRC = LegacyComponentSerializer.builder().flattener(FLATTENER).hexColors().useUnusualXRepeatedCharacterHexFormat().build(); + public static final PlainComponentSerializer PLAIN = PlainComponentSerializer.builder().flattener(FLATTENER).build(); -+ static final GsonComponentSerializer GSON = GsonComponentSerializer.builder() ++ public static final GsonComponentSerializer GSON = GsonComponentSerializer.builder() + .legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE) + .build(); ++ public static final GsonComponentSerializer COLOR_DOWNSAMPLING_GSON = GsonComponentSerializer.builder() ++ .legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.INSTANCE) ++ .downsampleColors() ++ .build(); + private static final Codec NBT_CODEC = new Codec() { + @Override + public @NonNull NBTTagCompound decode(final @NonNull String encoded) throws IOException { @@ -3149,6 +3153,26 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start + @Override ++ public net.kyori.adventure.text.flattener.ComponentFlattener componentFlattener() { ++ return io.papermc.paper.adventure.PaperAdventure.FLATTENER; ++ } ++ ++ @Override ++ public net.kyori.adventure.text.serializer.gson.GsonComponentSerializer colorDownsamplingGsonComponentSerializer() { ++ return io.papermc.paper.adventure.PaperAdventure.COLOR_DOWNSAMPLING_GSON; ++ } ++ ++ @Override ++ public net.kyori.adventure.text.serializer.gson.GsonComponentSerializer gsonComponentSerializer() { ++ return io.papermc.paper.adventure.PaperAdventure.GSON; ++ } ++ ++ @Override ++ public net.kyori.adventure.text.serializer.plain.PlainComponentSerializer plainComponentSerializer() { ++ return io.papermc.paper.adventure.PaperAdventure.PLAIN; ++ } ++ ++ @Override + public net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer legacyComponentSerializer() { + return io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC; + }