Fix wrong assumption about locale being null in the login phase (#11204)

Fixes #11203
This commit is contained in:
metabrix 2024-08-06 00:02:19 +05:00
parent 36c41877b6
commit f8f2bd7db7

View file

@ -2599,8 +2599,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- buf.writeUtf(Component.Serializer.toJson(this.reason, RegistryAccess.EMPTY));
+ // Paper start - Adventure
+ // buf.writeUtf(Component.Serializer.toJson(this.reason, RegistryAccess.EMPTY));
+ // In the login phase, buf.adventure$locale field is always null
+ buf.writeJsonWithCodec(net.minecraft.network.chat.ComponentSerialization.localizedCodec(java.util.Locale.US), this.reason, FriendlyByteBuf.MAX_COMPONENT_STRING_LENGTH);
+ // In the login phase, buf.adventure$locale field is most likely null, but plugins may use internals to set it via the channel attribute
+ java.util.Locale bufLocale = buf.adventure$locale;
+ buf.writeJsonWithCodec(net.minecraft.network.chat.ComponentSerialization.localizedCodec(bufLocale == null ? java.util.Locale.US : bufLocale), this.reason, FriendlyByteBuf.MAX_COMPONENT_STRING_LENGTH);
+ // Paper end - Adventure
}