Call Player#remove on server shutdown

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-09-21 19:30:36 +02:00
parent 5a4fc95ffd
commit e97f1db184
2 changed files with 5 additions and 14 deletions

View File

@ -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();

View File

@ -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) {