From 6db55ce91f76ae8f7fc41ab03b87e75972c4d9e3 Mon Sep 17 00:00:00 2001 From: TheMode Date: Tue, 3 Aug 2021 20:02:27 +0200 Subject: [PATCH] Always flip Signed-off-by: TheMode --- src/main/java/net/minestom/server/item/ItemMeta.java | 2 +- .../server/network/packet/server/play/ChunkDataPacket.java | 2 +- .../net/minestom/server/utils/binary/BinaryWriter.java | 7 ++----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/minestom/server/item/ItemMeta.java b/src/main/java/net/minestom/server/item/ItemMeta.java index 10c9381b0..3e5d2ad55 100644 --- a/src/main/java/net/minestom/server/item/ItemMeta.java +++ b/src/main/java/net/minestom/server/item/ItemMeta.java @@ -153,6 +153,6 @@ public class ItemMeta implements TagReadable, Writeable { w.writeNBT("", nbt); this.cachedBuffer = w.getBuffer(); } - writer.write(cachedBuffer.flip()); + writer.write(cachedBuffer); } } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ChunkDataPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ChunkDataPacket.java index 5fc4b7e2f..acd3f8b62 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ChunkDataPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ChunkDataPacket.java @@ -105,7 +105,7 @@ public class ChunkDataPacket implements ServerPacket { // Data writer.writeVarInt(blocks.position()); - writer.write(blocks.flip()); + writer.write(blocks); // Block entities if (entries == null || entries.isEmpty()) { diff --git a/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java b/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java index c45f5ee8b..3196a2de2 100644 --- a/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java +++ b/src/main/java/net/minestom/server/utils/binary/BinaryWriter.java @@ -288,14 +288,11 @@ public class BinaryWriter extends OutputStream { } public void write(@NotNull ByteBuffer buffer) { - this.buffer.put(buffer); + this.buffer.put(buffer.flip()); } public void write(@NotNull BinaryWriter writer) { - var buffer = writer.buffer; - final int pos = buffer.position(); - write(buffer.position(0)); - buffer.position(pos); + write(writer.buffer); } /**