Move warning to constructor

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-11-30 19:20:51 +01:00
parent 8f8ee4f7d2
commit 9a90018a8b

View File

@ -6,15 +6,18 @@ import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
public record ClientChatMessagePacket(@NotNull String message) implements ClientPacket {
public ClientChatMessagePacket {
if (message.length() > 256) {
throw new IllegalArgumentException("Message cannot be more than 256 characters long.");
}
}
public ClientChatMessagePacket(BinaryReader reader) {
this(reader.readSizedString(256));
}
@Override
public void write(@NotNull BinaryWriter writer) {
if (message.length() > 256) {
throw new IllegalArgumentException("Message cannot be more than 256 characters long.");
}
writer.writeSizedString(message);
}
}