66
77import com .comphenix .protocol .wrappers .codecs .WrappedCodec ;
88import com .comphenix .protocol .wrappers .codecs .WrappedDynamicOps ;
9- import com .google .gson .JsonElement ;
109import com .google .gson .JsonParseException ;
1110import com .google .gson .JsonParser ;
1211import org .bukkit .ChatColor ;
@@ -42,13 +41,15 @@ public class WrappedChatComponent extends AbstractWrapper implements ClonableWra
4241 private static ConstructorAccessor CONSTRUCT_TEXT_COMPONENT = null ;
4342
4443 private static WrappedCodec CODEC ;
44+ private static WrappedDynamicOps REGISTRY_JSON_OPS ;
4545
4646 static {
4747 FuzzyReflection fuzzy = FuzzyReflection .fromClass (SERIALIZER , true );
4848
4949 if (MinecraftVersion .v1_21_6 .atOrAbove ()) {
5050 Field codecField = fuzzy .getFieldByType ("CODEC" , MinecraftReflection .getCodecClass ());
5151 CODEC = WrappedCodec .fromHandle (Accessors .getFieldAccessor (codecField ).get (null ));
52+ REGISTRY_JSON_OPS = MinecraftRegistryAccess .createSerializationContext (WrappedDynamicOps .json (false ));
5253 } else if (MinecraftVersion .v1_20_5 .atOrAbove ()) {
5354 SERIALIZE_COMPONENT = Accessors .getMethodAccessor (fuzzy .getMethod (FuzzyMethodContract .newBuilder ()
5455 .returnTypeExact (String .class )
@@ -98,7 +99,7 @@ public class WrappedChatComponent extends AbstractWrapper implements ClonableWra
9899
99100 private static Object serialize (Object handle ) {
100101 if (CODEC != null ) {
101- Object jobj = CODEC .encode (handle , WrappedDynamicOps . json ( false ) ).getOrThrow (JsonParseException ::new );
102+ Object jobj = CODEC .encode (handle , REGISTRY_JSON_OPS ).getOrThrow (JsonParseException ::new );
102103 return jobj .toString ();
103104 }
104105
@@ -111,7 +112,7 @@ private static Object serialize(Object handle) {
111112
112113 private static Object deserialize (String json ) {
113114 if (CODEC != null ) {
114- return CODEC .parse (JsonParser .parseString (json ), WrappedDynamicOps . json ( false ) ).getOrThrow (JsonParseException ::new );
115+ return CODEC .parse (JsonParser .parseString (json ), REGISTRY_JSON_OPS ).getOrThrow (JsonParseException ::new );
115116 }
116117
117118 if (MinecraftVersion .v1_20_5 .atOrAbove ()) {
0 commit comments