From c4a4479602cfd33eabe7178b9af9ee8c7aba855e Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Fri, 5 Aug 2022 17:35:02 +0200 Subject: [PATCH] Fixed to make extra logic completely optional. --- .../src/main/java/nl/andrewl/aos2_server/Server.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/nl/andrewl/aos2_server/Server.java b/server/src/main/java/nl/andrewl/aos2_server/Server.java index 83ebafa..2481313 100644 --- a/server/src/main/java/nl/andrewl/aos2_server/Server.java +++ b/server/src/main/java/nl/andrewl/aos2_server/Server.java @@ -86,15 +86,18 @@ public class Server implements Runnable { running = true; new Thread(new UdpReceiver(datagramSocket, this::handleUdpMessage)).start(); new Thread(worldUpdater).start(); - ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); - var registryUpdater = new RegistryUpdater(this); - executorService.scheduleAtFixedRate(registryUpdater::sendUpdates, 0, 30, TimeUnit.SECONDS); + ScheduledExecutorService executorService = null; + if (config.registries != null && config.registries.length > 0) { + executorService = Executors.newSingleThreadScheduledExecutor(); + var registryUpdater = new RegistryUpdater(this); + executorService.scheduleAtFixedRate(registryUpdater::sendUpdates, 0, 30, TimeUnit.SECONDS); + } System.out.printf("Started AoS2 Server on TCP/UDP port %d; now accepting connections.%n", serverSocket.getLocalPort()); while (running) { acceptClientConnection(); } System.out.println("Shutting down the server."); - executorService.shutdown(); + if (executorService != null) executorService.shutdown(); playerManager.deregisterAll(); worldUpdater.shutdown(); datagramSocket.close(); // Shuts down the UdpReceiver.