Remove writeAndFlush

This commit is contained in:
themode 2022-03-20 02:35:45 +01:00
parent b304e1328a
commit 54fd65eded
4 changed files with 5 additions and 20 deletions

View File

@ -1305,11 +1305,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
} else {
disconnectPacket = new DisconnectPacket(component);
}
if (playerConnection instanceof PlayerSocketConnection) {
((PlayerSocketConnection) playerConnection).writeAndFlush(disconnectPacket);
} else {
playerConnection.sendPacket(disconnectPacket);
}
playerConnection.disconnect();
}

View File

@ -12,7 +12,6 @@ import net.minestom.server.network.packet.server.login.LoginSuccessPacket;
import net.minestom.server.network.packet.server.play.DisconnectPacket;
import net.minestom.server.network.packet.server.play.KeepAlivePacket;
import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.network.player.PlayerSocketConnection;
import net.minestom.server.utils.StringUtils;
import net.minestom.server.utils.async.AsyncUtils;
import net.minestom.server.utils.debug.DebugUtils;
@ -240,11 +239,7 @@ public final class ConnectionManager {
}
// Send login success packet
LoginSuccessPacket loginSuccessPacket = new LoginSuccessPacket(player.getUuid(), player.getUsername());
if (playerConnection instanceof PlayerSocketConnection socketConnection) {
socketConnection.writeAndFlush(loginSuccessPacket);
} else {
playerConnection.sendPacket(loginSuccessPacket);
}
playerConnection.setConnectionState(ConnectionState.PLAY);
if (register) registerPlayer(player);
this.waitingPlayers.relaxedOffer(player);

View File

@ -153,7 +153,7 @@ public class PlayerSocketConnection extends PlayerConnection {
Check.stateCondition(compressed, "Compression is already enabled!");
final int threshold = MinecraftServer.getCompressionThreshold();
Check.stateCondition(threshold == 0, "Compression cannot be enabled because the threshold is equal to 0");
writeAndFlush(new SetCompressionPacket(threshold));
sendPacket(new SetCompressionPacket(threshold));
this.compressed = true;
}
@ -182,14 +182,6 @@ public class PlayerSocketConnection extends PlayerConnection {
write(buffer, buffer.position(), buffer.remaining());
}
public void writeAndFlush(@NotNull ServerPacket packet) {
final boolean compressed = this.compressed;
this.workerQueue.relaxedOffer(() -> {
writeServerPacketSync(packet, compressed);
flushSync();
});
}
@Override
public void flush() {
this.workerQueue.relaxedOffer(this::flushSync);

View File

@ -83,6 +83,8 @@ public final class Worker extends MinestomThread {
public void disconnect(PlayerSocketConnection connection, SocketChannel channel) {
assert !connection.isOnline();
assert Thread.currentThread() == this;
connection.flushSync();
try {
channel.close();
this.connectionMap.remove(channel);