Fix item meta writing

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-08-03 19:44:10 +02:00
parent e4a3a3dbae
commit fbf6479135
5 changed files with 10 additions and 12 deletions

View File

@ -153,7 +153,6 @@ public class ItemMeta implements TagReadable, Writeable {
w.writeNBT("", nbt);
this.cachedBuffer = w.getBuffer();
}
writer.write(cachedBuffer);
this.cachedBuffer.position(0);
writer.write(cachedBuffer.flip());
}
}

View File

@ -211,9 +211,7 @@ public class NettyPlayerConnection extends PlayerConnection {
serverPacket = ((ComponentHoldingServerPacket) serverPacket).copyWithOperator(component ->
GlobalTranslator.render(component, Objects.requireNonNullElseGet(getPlayer().getLocale(), MinestomAdventure::getDefaultLocale)));
}
synchronized (tickBufferLock) {
PacketUtils.writeFramedPacket(tickBuffer, serverPacket);
}
attemptWrite(PacketUtils.createFramedPacket(serverPacket));
return;
} else if (message instanceof ByteBuffer) {
attemptWrite((ByteBuffer) message);

View File

@ -7,7 +7,6 @@ import net.minestom.server.network.player.NettyPlayerConnection;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
@ -140,7 +139,7 @@ public class Worker {
}
private static ByteBuffer allocate(int size) {
return ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
return ByteBuffer.allocateDirect(size);
}
}
}

View File

@ -2,7 +2,6 @@ package net.minestom.server.utils;
import it.unimi.dsi.fastutil.shorts.Short2ShortLinkedOpenHashMap;
import net.minestom.server.instance.palette.Palette;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@ -89,14 +88,14 @@ public final class Utils {
return result;
}
public static void writeVarLong(BinaryWriter writer, long value) {
public static void writeVarLong(ByteBuffer buffer, long value) {
do {
byte temp = (byte) (value & 0b01111111);
value >>>= 7;
if (value != 0) {
temp |= 0b10000000;
}
writer.writeByte(temp);
buffer.put(temp);
} while (value != 0);
}

View File

@ -150,7 +150,7 @@ public class BinaryWriter extends OutputStream {
* @param l the long to write
*/
public void writeVarLong(long l) {
Utils.writeVarLong(this, l);
Utils.writeVarLong(buffer, l);
}
/**
@ -292,7 +292,10 @@ public class BinaryWriter extends OutputStream {
}
public void write(@NotNull BinaryWriter writer) {
write(writer.getBuffer());
var buffer = writer.buffer;
final int pos = buffer.position();
write(buffer.position(0));
buffer.position(pos);
}
/**