Move string length check in ClientSettingsPacket

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-01-29 21:04:01 +01:00
parent f9080fa4f8
commit fb81578028

View File

@ -11,6 +11,11 @@ public record ClientSettingsPacket(@NotNull String locale, byte viewDistance,
@NotNull ChatMessageType chatMessageType, boolean chatColors, @NotNull ChatMessageType chatMessageType, boolean chatColors,
byte displayedSkinParts, @NotNull Player.MainHand mainHand, byte displayedSkinParts, @NotNull Player.MainHand mainHand,
boolean disableTextFiltering, boolean allowsListing) implements ClientPacket { boolean disableTextFiltering, boolean allowsListing) implements ClientPacket {
public ClientSettingsPacket {
if (locale.length() > 128)
throw new IllegalArgumentException("Locale cannot be longer than 128 characters.");
}
public ClientSettingsPacket(BinaryReader reader) { public ClientSettingsPacket(BinaryReader reader) {
this(reader.readSizedString(128), reader.readByte(), this(reader.readSizedString(128), reader.readByte(),
ChatMessageType.fromPacketID(reader.readVarInt()), reader.readBoolean(), ChatMessageType.fromPacketID(reader.readVarInt()), reader.readBoolean(),
@ -20,8 +25,6 @@ public record ClientSettingsPacket(@NotNull String locale, byte viewDistance,
@Override @Override
public void write(@NotNull BinaryWriter writer) { public void write(@NotNull BinaryWriter writer) {
if (locale.length() > 128)
throw new IllegalArgumentException("Locale cannot be longer than 128 characters.");
writer.writeSizedString(locale); writer.writeSizedString(locale);
writer.writeByte(viewDistance); writer.writeByte(viewDistance);
writer.writeVarInt(chatMessageType.getPacketID()); writer.writeVarInt(chatMessageType.getPacketID());