Merge pull request 'Implement proper stop and not sleep on BauCommand.stop' (#435) from VelocityCore/BauCommand#stop into main

Reviewed-on: SteamWar/SteamWar#435
Reviewed-by: D4rkr34lm <dark@steamwar.de>
This commit is contained in:
2026-06-17 21:23:33 +02:00
2 changed files with 29 additions and 6 deletions
@@ -80,7 +80,7 @@ public class Subserver {
static void shutdown() {
while (!serverList.isEmpty()) {
Subserver server = serverList.get(0);
server.stop();
server.sleep();
}
}
@@ -138,7 +138,7 @@ public class Subserver {
writer.println(command);
}
public void stop() {
public void sleep() {
try {
long pid = process.pid();
if (checkpoint) {
@@ -152,9 +152,32 @@ public class Subserver {
try {
if (!process.waitFor(1, TimeUnit.MINUTES)) {
forceStop();
}
} catch (InterruptedException e) {
logger.log(Level.SEVERE, "Subserver stop interrupted!", e);
Thread.currentThread().interrupt();
}
}
public void stop() {
try {
process.destroy();
if (!process.waitFor(1, TimeUnit.MINUTES)) {
forceStop();
} else if (thread.isAlive()) {
thread.join();
}
} catch (InterruptedException e) {
logger.log(Level.SEVERE, "Subserver stop interrupted!", e);
Thread.currentThread().interrupt();
}
}
public void forceStop() {
try {
logger.log(Level.SEVERE, () -> serverName + " did not stop correctly, forcibly stopping!");
process.destroyForcibly();
}
if (thread.isAlive()) thread.join();
} catch (InterruptedException e) {
@@ -196,7 +219,7 @@ public class Subserver {
protected void register() {
if (Persistent.getInstance().getProxy().getServer(serverName).isPresent()) {
SecurityException e = new SecurityException("Server already registered: " + serverName);
stop();
sleep();
failureCallback.accept(e);
throw e;
}
@@ -213,7 +213,7 @@ public class ServerStarter {
if (startingBau(owner)) return false;
Bauserver subserver = Bauserver.get(owner.getUniqueId());
if (subserver != null && subserver.isStarted()) subserver.stop();
if (subserver != null && subserver.isStarted()) subserver.sleep();
return !startingBau(owner);
};