mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 16:37:38 +01:00
Fix ghost player, trim chunk/light packets
This commit is contained in:
parent
538d641d4b
commit
120b58db6a
@ -133,8 +133,10 @@ public class DynamicChunk extends Chunk {
|
||||
if (connection instanceof NettyPlayerConnection) {
|
||||
final long lastChange = getLastChangeTime();
|
||||
if (lastChange > cachedPacketTime || (cachedChunkBuffer == null || cachedLightBuffer == null)) {
|
||||
this.cachedChunkBuffer = PacketUtils.createFramedPacket(ByteBuffer.allocate(65000), createChunkPacket());
|
||||
this.cachedLightBuffer = PacketUtils.createFramedPacket(ByteBuffer.allocate(65000), createLightPacket());
|
||||
final var tempChunk = PacketUtils.createFramedPacket(createChunkPacket());
|
||||
this.cachedChunkBuffer = ByteBuffer.allocate(tempChunk.position()).put(tempChunk.flip());
|
||||
final var tempLight = PacketUtils.createFramedPacket(createLightPacket());
|
||||
this.cachedLightBuffer = ByteBuffer.allocate(tempLight.position()).put(tempLight.flip());
|
||||
this.cachedPacketTime = lastChange;
|
||||
}
|
||||
NettyPlayerConnection nettyPlayerConnection = (NettyPlayerConnection) connection;
|
||||
|
@ -178,8 +178,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
*/
|
||||
@Override
|
||||
public void sendPacket(@NotNull ServerPacket serverPacket, boolean skipTranslating) {
|
||||
if (!channel.isConnected())
|
||||
return;
|
||||
if (!channel.isConnected()) return;
|
||||
if (shouldSendPacket(serverPacket)) {
|
||||
final Player player = getPlayer();
|
||||
if (player != null) {
|
||||
@ -207,7 +206,6 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
this.channel.write(tickBuffer.flip());
|
||||
this.tickBuffer.clear().put(buffer);
|
||||
} catch (IOException ex) {
|
||||
disconnect();
|
||||
MinecraftServer.getExceptionManager().handleException(ex);
|
||||
}
|
||||
}
|
||||
@ -229,7 +227,6 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
this.tickBuffer.clear();
|
||||
PacketUtils.writeFramedPacket(tickBuffer, packet, compressed);
|
||||
} catch (IOException ex) {
|
||||
disconnect();
|
||||
MinecraftServer.getExceptionManager().handleException(ex);
|
||||
}
|
||||
}
|
||||
@ -255,7 +252,6 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
this.channel.write(tickBuffer.flip());
|
||||
this.tickBuffer.clear();
|
||||
} catch (IOException e) {
|
||||
disconnect();
|
||||
MinecraftServer.getExceptionManager().handleException(e);
|
||||
}
|
||||
}
|
||||
|
@ -85,11 +85,9 @@ public final class Worker {
|
||||
}
|
||||
|
||||
public void disconnect(NettyPlayerConnection connection, SocketChannel channel) throws IOException {
|
||||
if (connectionMap.remove(channel) == null) return;
|
||||
// Client close
|
||||
connection.refreshOnline(false);
|
||||
channel.close();
|
||||
this.connectionMap.remove(channel);
|
||||
// Remove the connection
|
||||
connection.refreshOnline(false);
|
||||
Player player = connection.getPlayer();
|
||||
if (player != null) {
|
||||
|
@ -102,7 +102,6 @@ public final class PacketUtils {
|
||||
connection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
finalBuffer.clear(); // Clear packet to be reused
|
||||
} else {
|
||||
// Write the same packet for each individual players
|
||||
for (Player player : players) {
|
||||
@ -179,6 +178,6 @@ public final class PacketUtils {
|
||||
}
|
||||
|
||||
public static ByteBuffer createFramedPacket(@NotNull ServerPacket packet) {
|
||||
return createFramedPacket(BUFFER.get(), packet);
|
||||
return createFramedPacket(BUFFER.get().clear(), packet);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user