mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Fix buffer offset
This commit is contained in:
parent
ec66beece4
commit
6520855418
@ -207,7 +207,7 @@ public final class PacketUtils {
|
|||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public static FramedPacket allocateTrimmedPacket(@NotNull ServerPacket packet) {
|
public static FramedPacket allocateTrimmedPacket(@NotNull ServerPacket packet) {
|
||||||
final var temp = PacketUtils.createFramedPacket(packet);
|
final var temp = PacketUtils.createFramedPacket(packet);
|
||||||
final var buffer= ByteBuffer.allocateDirect(temp.position()).put(temp.flip()).asReadOnlyBuffer();
|
final var buffer = ByteBuffer.allocateDirect(temp.position()).put(temp.flip()).asReadOnlyBuffer();
|
||||||
return new FramedPacket(packet.getId(), buffer, packet);
|
return new FramedPacket(packet.getId(), buffer, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,13 +277,11 @@ public final class PacketUtils {
|
|||||||
Consumer<ByteBuffer> writer = connection instanceof PlayerSocketConnection
|
Consumer<ByteBuffer> writer = connection instanceof PlayerSocketConnection
|
||||||
? ((PlayerSocketConnection) connection)::write :
|
? ((PlayerSocketConnection) connection)::write :
|
||||||
byteBuffer -> {
|
byteBuffer -> {
|
||||||
System.out.println("error");
|
|
||||||
// TODO for non-socket connection
|
// TODO for non-socket connection
|
||||||
};
|
};
|
||||||
|
|
||||||
final var pair = entityIdMap.get(connection);
|
final var pair = entityIdMap.get(connection);
|
||||||
if (pair != null) {
|
if (pair != null) {
|
||||||
System.out.println("not null");
|
|
||||||
final int start = pair.leftInt();
|
final int start = pair.leftInt();
|
||||||
final int end = pair.rightInt();
|
final int end = pair.rightInt();
|
||||||
if (start == 0) {
|
if (start == 0) {
|
||||||
@ -295,9 +293,8 @@ public final class PacketUtils {
|
|||||||
writer.accept(buffer.asByteBuffer(end, readable - end));
|
writer.accept(buffer.asByteBuffer(end, readable - end));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ByteBuffer result = buffer.asByteBuffer(buffer.writerOffset(), buffer.writerOffset());
|
ByteBuffer result = buffer.asByteBuffer(0, buffer.writerOffset());
|
||||||
result.position(result.limit());
|
result.position(result.limit());
|
||||||
//System.out.println("write "+result);
|
|
||||||
writer.accept(result);
|
writer.accept(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -327,13 +324,11 @@ public final class PacketUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void flush() {
|
public static void flush() {
|
||||||
var map = VIEWABLE_STORAGE_MAP;
|
final var map = VIEWABLE_STORAGE_MAP;
|
||||||
VIEWABLE_STORAGE_MAP = new ConcurrentHashMap<>();
|
VIEWABLE_STORAGE_MAP = new ConcurrentHashMap<>();
|
||||||
map.values().forEach(viewableStorage -> {
|
for (ViewableStorage viewableStorage : map.values()) {
|
||||||
if (viewableStorage.entries.isEmpty()) {
|
if (viewableStorage.entries.isEmpty()) continue;
|
||||||
return; // nothing to flush
|
|
||||||
}
|
|
||||||
viewableStorage.process();
|
viewableStorage.process();
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user