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);
}

View File

@@ -1,5 +1,7 @@
package net.packet;
import net.opcodes.SendOpcode;
import java.awt.*;
public interface OutPacket extends Packet {
@@ -9,8 +11,12 @@ public interface OutPacket extends Packet {
void writeShort(int value);
void writeInt(int value);
void writeLong(long value);
void writeBoolean(boolean value);
void writeBool(boolean value);
void writeString(String value);
void writePoint(Point value);
void skip(int numberOfBytes);
static OutPacket create(SendOpcode opcode) {
return new ByteBufOutPacket(opcode);
}
}