3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Made the server kick all players before we shutdown and close the window when we finish on standalone.

Dieser Commit ist enthalten in:
rtm516 2020-04-06 14:33:36 +01:00
Ursprung 16388a1f85
Commit d4fa651427
2 geänderte Dateien mit 43 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -49,6 +49,7 @@ import java.net.InetSocketAddress;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -141,6 +142,41 @@ public class GeyserConnector {
bootstrap.getGeyserLogger().info("Shutting down Geyser."); bootstrap.getGeyserLogger().info("Shutting down Geyser.");
shuttingDown = true; shuttingDown = true;
if (players.size() >= 1) {
bootstrap.getGeyserLogger().info("Kicking " + players.size() + " players");
for (GeyserSession playerSession : players.values()) {
playerSession.disconnect("Geyser Proxy shutting down.");
}
CompletableFuture<Void> future = CompletableFuture.runAsync(new Runnable() {
@Override
public void run() {
// Simulate a long-running Job
try {
while (true) {
bootstrap.getGeyserLogger().info("Current entries: " + players.size());
if (players.size() == 0) {
return;
}
TimeUnit.MILLISECONDS.sleep(100);
}
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
}
});
// Block and wait for the future to complete
try {
future.get();
bootstrap.getGeyserLogger().info("Kicked all players");
} catch (Exception e) {
// Quietly fail
}
}
generalThreadPool.shutdown(); generalThreadPool.shutdown();
bedrockServer.close(); bedrockServer.close();
players.clear(); players.clear();
@ -148,6 +184,8 @@ public class GeyserConnector {
authType = null; authType = null;
commandMap.getCommands().clear(); commandMap.getCommands().clear();
commandMap = null; commandMap = null;
bootstrap.getGeyserLogger().info("Geyser shutdown successfully.");
} }
public void addPlayer(GeyserSession player) { public void addPlayer(GeyserSession player) {

Datei anzeigen

@ -48,6 +48,11 @@ public class StopCommand extends GeyserCommand {
if (!sender.isConsole() && connector.getPlatformType() == PlatformType.STANDALONE) { if (!sender.isConsole() && connector.getPlatformType() == PlatformType.STANDALONE) {
return; return;
} }
connector.shutdown(); connector.shutdown();
if (connector.getPlatformType() == PlatformType.STANDALONE) {
System.exit(0);
}
} }
} }