aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0010-Adventure.patch
diff options
context:
space:
mode:
authorJake Potrebic <[email protected]>2024-06-16 12:39:59 -0700
committerGitHub <[email protected]>2024-06-16 12:39:59 -0700
commitd9111ccec278132052cebdebca9f1c6dcaba9512 (patch)
tree371066574c947f764742e741e5a0238f69d49305 /patches/server/0010-Adventure.patch
parent106dbae220686b2a01abf570a7925757940f68a3 (diff)
downloadPaper-d9111ccec278132052cebdebca9f1c6dcaba9512.tar.gz
Paper-d9111ccec278132052cebdebca9f1c6dcaba9512.zip
Registry Modification API (#10893)
* Registry Modification API * some fixes * even more fixes
Diffstat (limited to 'patches/server/0010-Adventure.patch')
-rw-r--r--patches/server/0010-Adventure.patch26
1 files changed, 18 insertions, 8 deletions
diff --git a/patches/server/0010-Adventure.patch b/patches/server/0010-Adventure.patch
index 75e61f1b24..c6a160a49b 100644
--- a/patches/server/0010-Adventure.patch
+++ b/patches/server/0010-Adventure.patch
@@ -1157,15 +1157,16 @@ index 0000000000000000000000000000000000000000..2fd6c3e65354071af71c7d8ebb97b559
+}
diff --git a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
new file mode 100644
-index 0000000000000000000000000000000000000000..a6aef1ac31f3d2784b5d7b1af616965b5cd2c383
+index 0000000000000000000000000000000000000000..dc4837c577676115f0653acc35f55962a432e425
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
-@@ -0,0 +1,478 @@
+@@ -0,0 +1,479 @@
+package io.papermc.paper.adventure;
+
+import com.mojang.brigadier.StringReader;
+import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import com.mojang.serialization.JavaOps;
++import com.mojang.serialization.JsonOps;
+import io.netty.util.AttributeKey;
+import java.io.IOException;
+import java.util.ArrayList;
@@ -1302,7 +1303,7 @@ index 0000000000000000000000000000000000000000..a6aef1ac31f3d2784b5d7b1af616965b
+ return decoded.toString();
+ }
+ };
-+ public static final ComponentSerializer<Component, Component, net.minecraft.network.chat.Component> WRAPPER_AWARE_SERIALIZER = new WrapperAwareSerializer();
++ public static final ComponentSerializer<Component, Component, net.minecraft.network.chat.Component> WRAPPER_AWARE_SERIALIZER = new WrapperAwareSerializer(() -> CraftRegistry.getMinecraftRegistry().createSerializationContext(JavaOps.INSTANCE));
+
+ private PaperAdventure() {
+ }
@@ -1641,27 +1642,36 @@ index 0000000000000000000000000000000000000000..a6aef1ac31f3d2784b5d7b1af616965b
+}
diff --git a/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java b/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java
new file mode 100644
-index 0000000000000000000000000000000000000000..c786ddf0ef19757011452204fd11d24541c39d9e
+index 0000000000000000000000000000000000000000..a16344476abbb4f3e8aac26d4add9da53b7fc7df
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/WrapperAwareSerializer.java
-@@ -0,0 +1,34 @@
+@@ -0,0 +1,43 @@
+package io.papermc.paper.adventure;
+
++import com.google.common.base.Suppliers;
+import com.mojang.datafixers.util.Pair;
+import com.mojang.serialization.JavaOps;
++import java.util.function.Supplier;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.serializer.ComponentSerializer;
+import net.minecraft.network.chat.ComponentSerialization;
+import net.minecraft.resources.RegistryOps;
+import org.bukkit.craftbukkit.CraftRegistry;
+
-+final class WrapperAwareSerializer implements ComponentSerializer<Component, Component, net.minecraft.network.chat.Component> {
++public final class WrapperAwareSerializer implements ComponentSerializer<Component, Component, net.minecraft.network.chat.Component> {
++
++ private final Supplier<RegistryOps<Object>> javaOps;
++
++ public WrapperAwareSerializer(final Supplier<RegistryOps<Object>> javaOps) {
++ this.javaOps = Suppliers.memoize(javaOps::get);
++ }
++
+ @Override
+ public Component deserialize(final net.minecraft.network.chat.Component input) {
+ if (input instanceof AdventureComponent) {
+ return ((AdventureComponent) input).adventure;
+ }
-+ final RegistryOps<Object> ops = CraftRegistry.getMinecraftRegistry().createSerializationContext(JavaOps.INSTANCE);
++ final RegistryOps<Object> ops = this.javaOps.get();
+ final Object obj = ComponentSerialization.CODEC.encodeStart(ops, input)
+ .getOrThrow(s -> new RuntimeException("Failed to encode Minecraft Component: " + input + "; " + s));
+ final Pair<Component, Object> converted = AdventureCodecs.COMPONENT_CODEC.decode(ops, obj)
@@ -1671,7 +1681,7 @@ index 0000000000000000000000000000000000000000..c786ddf0ef19757011452204fd11d245
+
+ @Override
+ public net.minecraft.network.chat.Component serialize(final Component component) {
-+ final RegistryOps<Object> ops = CraftRegistry.getMinecraftRegistry().createSerializationContext(JavaOps.INSTANCE);
++ final RegistryOps<Object> ops = this.javaOps.get();
+ final Object obj = AdventureCodecs.COMPONENT_CODEC.encodeStart(ops, component)
+ .getOrThrow(s -> new RuntimeException("Failed to encode adventure Component: " + component + "; " + s));
+ final Pair<net.minecraft.network.chat.Component, Object> converted = ComponentSerialization.CODEC.decode(ops, obj)