From dcfd25836bcc985323be251cfb8161e732185e4f Mon Sep 17 00:00:00 2001 From: Shane Freeder Date: Fri, 7 Nov 2025 00:08:47 +0000 Subject: [PATCH] Evil attempt at ensuring we coax logger to flush --- .../com/velocitypowered/proxy/Velocity.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java b/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java index a6fc850b8..6eff3ef1b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java @@ -70,20 +70,31 @@ public class Velocity { return; } + final VelocityServer[] velocity = {null}; + + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + if (velocity[0] != null) { + velocity[0].shutdown(true); + } else { + LogManager.shutdown(); + } + }, "Shutdown thread")); + long startTime = System.nanoTime(); - VelocityServer server = new VelocityServer(options); - server.start(); - Runtime.getRuntime().addShutdownHook(new Thread(() -> server.shutdown(false), - "Shutdown thread")); + + velocity[0] = new VelocityServer(options); + velocity[0].start(); + + double bootTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime) / 1000d; logger.info("Done ({}s)!", new DecimalFormat("#.##").format(bootTime)); - server.getConsoleCommandSource().start(); + velocity[0].getConsoleCommandSource().start(); // If we don't have a console available (because SimpleTerminalConsole returned), then we still // need to wait, otherwise the JVM will reap us as no non-daemon threads will be active once the // main thread exits. - server.awaitProxyShutdown(); + velocity[0].awaitProxyShutdown(); } }