geforkt von Mirrors/Paper
Expose more Adventure serializers through PaperComponents (#5443)
Dieser Commit ist enthalten in:
Ursprung
9285c76055
Commit
bf974a611b
@ -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.
|
||||
+ *
|
||||
+ * <p>Implementations may provide a serializer capable of processing any
|
||||
+ * information that requires access to implementation details.</p>
|
||||
+ *
|
||||
+ * @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.
|
||||
+ *
|
||||
+ * <p>Implementations may provide a serializer capable of processing any
|
||||
+ * information that requires implementation details, such as legacy
|
||||
+ * (pre-1.16) hover events.</p>
|
||||
+ *
|
||||
+ * @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.
|
||||
+ *
|
||||
+ * <p>Implementations may provide a serializer capable of processing any
|
||||
+ * information that requires implementation details, such as legacy
|
||||
+ * (pre-1.16) hover events.</p>
|
||||
+ *
|
||||
+ * @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.
|
||||
+ *
|
||||
+ * <p>This legacy serializer uses the standard section symbol to mark
|
||||
+ * formatting characters.</p>
|
||||
+ *
|
||||
+ * <p>Implementations may provide a serializer capable of processing any
|
||||
+ * information that requires access to implementation details.</p>
|
||||
+ *
|
||||
+ * @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);
|
||||
|
@ -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<NBTTagCompound, String, IOException, IOException> NBT_CODEC = new Codec<NBTTagCompound, String, IOException, IOException>() {
|
||||
+ @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;
|
||||
+ }
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren