Tweak OutPacket

This commit is contained in:
P0nk
2021-08-20 12:18:59 +02:00
parent e93428f457
commit d8b0929975
5 changed files with 34 additions and 10 deletions

View File

@@ -11,6 +11,7 @@ import java.awt.*;
@NotThreadSafe
public class ByteBufOutPacket implements OutPacket {
private final ByteBuf byteBuf;
private byte[] bytes;
@Deprecated(forRemoval = true)
public ByteBufOutPacket() {
@@ -31,7 +32,12 @@ public class ByteBufOutPacket implements OutPacket {
@Override
public byte[] getBytes() {
return ByteBufUtil.getBytes(byteBuf);
if (bytes == null) {
// Avoid creating new byte arrays when the packet is broadcast
bytes = ByteBufUtil.getBytes(byteBuf);
}
return bytes;
}
@Override
@@ -65,7 +71,7 @@ public class ByteBufOutPacket implements OutPacket {
}
@Override
public void writeBoolean(boolean value) {
public void writeBool(boolean value) {
byteBuf.writeByte(value ? 1 : 0);
}