From 392bf0ee6b1358cb295dc270b27eec2d6e3c56f5 Mon Sep 17 00:00:00 2001 From: Kurt Thiemann Date: Fri, 30 Jul 2021 13:57:09 +0200 Subject: [PATCH] run async tasks together --- .../com/exaroton/bungee/ExarotonPlugin.java | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/exaroton/bungee/ExarotonPlugin.java b/src/main/java/com/exaroton/bungee/ExarotonPlugin.java index 331e0b2..fc8f264 100644 --- a/src/main/java/com/exaroton/bungee/ExarotonPlugin.java +++ b/src/main/java/com/exaroton/bungee/ExarotonPlugin.java @@ -65,8 +65,7 @@ public void onEnable() { } if (this.createExarotonClient()) { this.registerCommands(); - this.startWatchingServers(); - this.autoStartServers(); + this.runAsyncTasks(); } } @@ -259,10 +258,13 @@ public void listenToStatus(Server server, CommandSender sender, String name) { /** * start watching servers in the bungee config */ - public void startWatchingServers() { - if (config.getBoolean("watch-servers")) { - this.getProxy().getScheduler().runAsync(this, this::watchServers); - } + public void runAsyncTasks() { + this.getProxy().getScheduler().runAsync(this, () -> { + if(config.getBoolean("watch-servers")) { + this.watchServers(); + } + this.autoStartServers(); + }); } /** @@ -299,37 +301,35 @@ public void watchServers() { */ public void autoStartServers() { if (!config.getBoolean("auto-start.enabled")) return; - this.getProxy().getScheduler().runAsync(this, () -> { - for (String query: config.getStringList("auto-start.servers")) { - try { - Server server = this.findServer(query); - - if (server == null) { - logger.log(Level.WARNING, "Can't start " + query + ": Server not found"); - continue; - } - - if (server.hasStatus(new int[]{ServerStatus.ONLINE, ServerStatus.STARTING, - ServerStatus.LOADING, ServerStatus.PREPARING, ServerStatus.RESTARTING})) { - logger.log(Level.INFO, server.getAddress() + " is already online or starting!"); - this.listenToStatus(server, null, findServerName(server.getAddress())); - return; - } + for (String query: config.getStringList("auto-start.servers")) { + try { + Server server = this.findServer(query); - if (!server.hasStatus(new int[]{ServerStatus.OFFLINE, ServerStatus.CRASHED})) { - logger.log(Level.SEVERE, "Can't start " + server.getAddress() + ": Server isn't offline."); - continue; - } + if (server == null) { + logger.log(Level.WARNING, "Can't start " + query + ": Server not found"); + continue; + } - logger.log(Level.INFO, "Starting "+ server.getAddress()); + if (server.hasStatus(new int[]{ServerStatus.ONLINE, ServerStatus.STARTING, + ServerStatus.LOADING, ServerStatus.PREPARING, ServerStatus.RESTARTING})) { + logger.log(Level.INFO, server.getAddress() + " is already online or starting!"); this.listenToStatus(server, null, findServerName(server.getAddress())); - server.start(); + return; + } - } catch (APIException e) { - logger.log(Level.SEVERE, "Failed to start start "+ query +"!", e); + if (!server.hasStatus(new int[]{ServerStatus.OFFLINE, ServerStatus.CRASHED})) { + logger.log(Level.SEVERE, "Can't start " + server.getAddress() + ": Server isn't offline."); + continue; } + + logger.log(Level.INFO, "Starting "+ server.getAddress()); + this.listenToStatus(server, null, findServerName(server.getAddress())); + server.start(); + + } catch (APIException e) { + logger.log(Level.SEVERE, "Failed to start start "+ query +"!", e); } - }); + } } /**