mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Merge pull request #274 from rtm516/shutdown-fix
Kick players on shutdown and fix window not closing on standalone
This commit is contained in:
commit
ece1eeb451
3 changed files with 43 additions and 1 deletions
|
@ -52,7 +52,7 @@ public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void shutdown() {
|
protected void shutdown() {
|
||||||
GeyserConnector.getInstance().shutdown();
|
GeyserConnector.getInstance().getBootstrap().onDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -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.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
@ -142,6 +143,40 @@ 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() + " player(s)");
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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();
|
||||||
|
@ -149,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) {
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue