mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 13:08:19 +01:00
Do not flip the buffer inside #write(ByteBuffer)
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
885be567fa
commit
7b8277b6be
@ -132,8 +132,8 @@ public class DynamicChunk extends Chunk {
|
||||
final FramedPacket chunkPacket = chunkCache.retrieveFramedPacket(lastChange);
|
||||
if (connection instanceof PlayerSocketConnection) {
|
||||
PlayerSocketConnection socketConnection = (PlayerSocketConnection) connection;
|
||||
socketConnection.write(lightPacket.body());
|
||||
socketConnection.write(chunkPacket.body());
|
||||
socketConnection.write(lightPacket);
|
||||
socketConnection.write(chunkPacket);
|
||||
} else {
|
||||
connection.sendPacket(lightPacket.packet());
|
||||
connection.sendPacket(chunkPacket.packet());
|
||||
|
@ -230,15 +230,14 @@ public class PlayerSocketConnection extends PlayerConnection {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public void write(@NotNull ByteBuffer buffer) {
|
||||
synchronized (bufferLock) {
|
||||
final int size = buffer.position();
|
||||
final int size = buffer.remaining();
|
||||
if (size <= BUFFER_SIZE) {
|
||||
if (!tickBuffer.canWrite(size)) flush();
|
||||
this.tickBuffer.write(buffer.flip());
|
||||
this.tickBuffer.write(buffer);
|
||||
} else {
|
||||
final int positionCache = buffer.position();
|
||||
final int limitCache = buffer.limit();
|
||||
final int bufferCount = size / BUFFER_SIZE + 1;
|
||||
for (int i = 0; i < bufferCount; i++) {
|
||||
buffer.position(i * BUFFER_SIZE);
|
||||
@ -246,17 +245,16 @@ public class PlayerSocketConnection extends PlayerConnection {
|
||||
if (!tickBuffer.canWrite(buffer.remaining())) flush();
|
||||
this.tickBuffer.write(buffer);
|
||||
}
|
||||
buffer.position(positionCache).limit(limitCache);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void write(@NotNull FramedPacket framedPacket) {
|
||||
write(framedPacket.body());
|
||||
write(framedPacket.body().flip());
|
||||
}
|
||||
|
||||
public void write(@NotNull ServerPacket packet) {
|
||||
write(PacketUtils.createFramedPacket(packet, compressed));
|
||||
write(PacketUtils.createFramedPacket(packet, compressed).flip());
|
||||
}
|
||||
|
||||
public void writeAndFlush(@NotNull ServerPacket packet) {
|
||||
|
@ -308,7 +308,6 @@ public final class PacketUtils {
|
||||
final int start = pair.leftInt();
|
||||
if (start != lastWrite) {
|
||||
ByteBuffer slice = buffer.asByteBuffer(lastWrite, start);
|
||||
slice.position(slice.limit());
|
||||
writer.accept(slice);
|
||||
}
|
||||
lastWrite = pair.rightInt();
|
||||
@ -318,7 +317,6 @@ public final class PacketUtils {
|
||||
final int remaining = buffer.writerOffset() - lastWrite;
|
||||
if (remaining > 0) {
|
||||
ByteBuffer remainSlice = buffer.asByteBuffer(lastWrite, remaining);
|
||||
remainSlice.position(remainSlice.limit());
|
||||
writer.accept(remainSlice);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user