From e97f1db1842fb33b74e4e26e3e6ab534912acf6e Mon Sep 17 00:00:00 2001 From: TheMode Date: Tue, 21 Sep 2021 19:30:36 +0200 Subject: [PATCH] Call Player#remove on server shutdown Signed-off-by: TheMode --- .../server/network/ConnectionManager.java | 17 ++++------------- .../minestom/server/network/socket/Worker.java | 2 +- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/minestom/server/network/ConnectionManager.java b/src/main/java/net/minestom/server/network/ConnectionManager.java index f9a49c2aa..f935d8559 100644 --- a/src/main/java/net/minestom/server/network/ConnectionManager.java +++ b/src/main/java/net/minestom/server/network/ConnectionManager.java @@ -23,7 +23,6 @@ import net.minestom.server.utils.validate.Check; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.IOException; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; @@ -346,18 +345,10 @@ public final class ConnectionManager { DisconnectPacket disconnectPacket = new DisconnectPacket(shutdownText); for (Player player : getOnlinePlayers()) { final PlayerConnection playerConnection = player.getPlayerConnection(); - if (playerConnection instanceof PlayerSocketConnection) { - final PlayerSocketConnection socketConnection = (PlayerSocketConnection) playerConnection; - socketConnection.writeAndFlush(disconnectPacket); - playerConnection.disconnect(); - try { - socketConnection.getChannel().close(); - } catch (IOException e) { - e.printStackTrace(); - } - } else { - player.remove(); - } + playerConnection.sendPacket(disconnectPacket); + playerConnection.flush(); + player.remove(); + playerConnection.disconnect(); } this.players.clear(); this.connectionPlayerMap.clear(); diff --git a/src/main/java/net/minestom/server/network/socket/Worker.java b/src/main/java/net/minestom/server/network/socket/Worker.java index 66a97be9d..b5f627ee7 100644 --- a/src/main/java/net/minestom/server/network/socket/Worker.java +++ b/src/main/java/net/minestom/server/network/socket/Worker.java @@ -68,7 +68,7 @@ public final class Worker extends Thread { MinecraftServer.getConnectionManager().removePlayer(connection); connection.refreshOnline(false); Player player = connection.getPlayer(); - if (player != null) { + if (player != null && !player.isRemoved()) { player.scheduleNextTick(Entity::remove); } } catch (IOException e) {