Merge branch 'master' into viewable-broadcast

# Conflicts:
#	src/main/java/net/minestom/server/network/player/PlayerSocketConnection.java
This commit is contained in:
TheMode 2021-09-03 14:01:39 +02:00
commit e19b49db55
2 changed files with 15 additions and 3 deletions

View File

@ -124,7 +124,7 @@ public class DynamicChunk extends Chunk {
}
@Override
public void sendChunk(@NotNull Player player) {
public synchronized void sendChunk(@NotNull Player player) {
if (!isLoaded()) return;
final PlayerConnection connection = player.getPlayerConnection();
final long lastChange = getLastChangeTime();
@ -141,7 +141,7 @@ public class DynamicChunk extends Chunk {
}
@Override
public void sendChunk() {
public synchronized void sendChunk() {
if (!isLoaded()) return;
if (getViewers().isEmpty()) return;
final long lastChange = getLastChangeTime();

View File

@ -75,7 +75,7 @@ public class PlayerSocketConnection extends PlayerConnection {
private final Object bufferLock = new Object();
private final List<BinaryBuffer> waitingBuffers = new ArrayList<>();
private BinaryBuffer tickBuffer = BinaryBuffer.ofSize(BUFFER_SIZE);
private BinaryBuffer tickBuffer = getPooledBuffer();
private volatile BinaryBuffer cacheBuffer;
public PlayerSocketConnection(@NotNull Worker worker, @NotNull SocketChannel channel, SocketAddress remoteAddress) {
@ -300,6 +300,8 @@ public class PlayerSocketConnection extends PlayerConnection {
}
}
}
// Update tick buffer
this.tickBuffer = getPooledBuffer();
}
}
@ -460,4 +462,14 @@ public class PlayerSocketConnection extends PlayerConnection {
public void setNonce(byte[] nonce) {
this.nonce = nonce;
}
private static BinaryBuffer getPooledBuffer() {
BinaryBuffer newBuffer = POOLED_BUFFERS.poll();
if (newBuffer == null) {
newBuffer = BinaryBuffer.ofSize(BUFFER_SIZE);
} else {
newBuffer.clear();
}
return newBuffer;
}
}