This commit is contained in:
themode 2020-11-18 06:39:20 +01:00
parent 2a1a1cdcbc
commit 40d6a71697
3 changed files with 15 additions and 4 deletions

View File

@ -93,9 +93,9 @@ public class StorageLocation {
Check.notNull(dataType, "You can only save registered DataType type!");
// Encode the data
BinaryWriter binaryWriter = new BinaryWriter();
dataType.encode(binaryWriter, object); // Encode
final byte[] encodedValue = binaryWriter.toByteArray(); // Retrieve bytes
BinaryWriter writer = new BinaryWriter();
dataType.encode(writer, object); // Encode
final byte[] encodedValue = writer.toByteArray(); // Retrieve bytes
// Write it
set(key, encodedValue);

View File

@ -74,6 +74,7 @@ public final class PacketUtils {
private static void writePacket(@NotNull ByteBuf buf, @NotNull ByteBuf packetBuffer, int packetId) {
Utils.writeVarIntBuf(buf, packetId);
buf.writeBytes(packetBuffer);
packetBuffer.release();
}
/**

View File

@ -7,6 +7,7 @@ import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.NBTUtils;
import net.minestom.server.utils.SerializerUtils;
import net.minestom.server.utils.Utils;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.NBTWriter;
@ -34,12 +35,21 @@ public class BinaryWriter extends OutputStream {
this.buffer = Unpooled.buffer(initialCapacity);
}
/**
* Creates a {@link BinaryWriter} from multiple a single buffer.
*
* @param buffer the writer buffer
*/
public BinaryWriter(@NotNull ByteBuf buffer) {
this.buffer = buffer;
}
/**
* Creates a {@link BinaryWriter} from multiple buffers.
*
* @param buffers the buffers making this
*/
public BinaryWriter(ByteBuf... buffers) {
public BinaryWriter(@NotNull ByteBuf... buffers) {
this.buffer = Unpooled.wrappedBuffer(buffers);
}