package io.papermc.paper.text; import java.io.IOException; 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 net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; import org.jspecify.annotations.NullMarked; import org.jspecify.annotations.Nullable; /** * Paper API-specific methods for working with {@link Component}s and related. */ @NullMarked public final class PaperComponents { private PaperComponents() { throw new RuntimeException("PaperComponents is not to be instantiated!"); } /** * Resolves a component with a specific command sender and subject. *
* Note that in Vanilla, elevated permissions are usually required to use * '@' selectors in various component types, but this method should not * check such permissions from the sender. *
* A {@link CommandSender} argument is required to resolve: *
* Note that in Vanilla, elevated permissions are required to use * '@' selectors in various component types. If the boolean {@code bypassPermissions} * argument is {@code false}, the {@link CommandSender} argument will be used to query * those permissions. *
* A {@link CommandSender} argument is required to resolve: *
Implementations may provide a serializer capable of processing any * information that requires access to implementation details.
* * @return a serializer to plain text * @deprecated will be removed in adventure 5.0.0, use {@link PlainTextComponentSerializer#plainText()} */ @Deprecated(forRemoval = true, since = "1.18.1") public static PlainComponentSerializer plainSerializer() { return Bukkit.getUnsafe().plainComponentSerializer(); } /** * 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 * @deprecated use {@link PlainTextComponentSerializer#plainText()} */ @Deprecated(forRemoval = true, since = "1.18.2") public static PlainTextComponentSerializer plainTextSerializer() { return Bukkit.getUnsafe().plainTextSerializer(); } /** * 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 * @deprecated use {@link GsonComponentSerializer#gson()} */ @Deprecated(forRemoval = true, since = "1.18.2") public static 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 * @deprecated use {@link GsonComponentSerializer#colorDownsamplingGson()} */ @Deprecated(forRemoval = true, since = "1.18.2") public static 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 * @deprecated use {@link LegacyComponentSerializer#legacySection()} */ @Deprecated(forRemoval = true, since = "1.18.2") public static LegacyComponentSerializer legacySectionSerializer() { return Bukkit.getUnsafe().legacyComponentSerializer(); } }