diff --git a/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java index cec64eec5..3b3545423 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/PlanCommand.java @@ -50,10 +50,8 @@ public class PlanCommand extends TreeCommand { RegisterCommand registerCommand = new RegisterCommand(plugin); commands.add(registerCommand); commands.add(new WebUserCommand(plugin, registerCommand)); - if (plugin.getInfoManager().isUsingAnotherWebServer()) { - commands.add(new NetworkCommand()); - commands.add(new ListServersCommand(plugin)); - } + commands.add(new NetworkCommand(plugin)); + commands.add(new ListServersCommand(plugin)); if (Settings.DEV_MODE.isTrue()) { commands.add(new DevCommand(plugin)); diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/NetworkCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/NetworkCommand.java index 741fbaf39..0b147ba3a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/NetworkCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/NetworkCommand.java @@ -19,17 +19,22 @@ import main.java.com.djrapitops.plan.locale.Msg; */ public class NetworkCommand extends SubCommand { + private final Plan plugin; + /** * Class Constructor. */ - public NetworkCommand() { + public NetworkCommand(Plan plugin) { super("network, n, netw", CommandType.CONSOLE, Permissions.ANALYZE.getPermission(), Locale.get(Msg.CMD_USG_LIST).toString(), ""); - + this.plugin = plugin; } @Override public boolean onCommand(ISender sender, String commandLabel, String[] args) { - + if (plugin.getInfoManager().isUsingAnotherWebServer()) { + sender.sendMessage("§cNot using Bungee WebServer!"); + return true; + } sendNetworkMsg(sender); return true; } diff --git a/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java b/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java index 688ad5f50..4b77d9c4c 100644 --- a/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java +++ b/Plan/src/main/java/com/djrapitops/plan/systems/info/BukkitInformationManager.java @@ -19,6 +19,7 @@ import main.java.com.djrapitops.plan.systems.info.parsing.AnalysisPageParser; import main.java.com.djrapitops.plan.systems.info.parsing.InspectPageParser; import main.java.com.djrapitops.plan.systems.processing.Processor; import main.java.com.djrapitops.plan.systems.webserver.PageCache; +import main.java.com.djrapitops.plan.systems.webserver.WebServer; import main.java.com.djrapitops.plan.systems.webserver.response.AnalysisPageResponse; import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse; import main.java.com.djrapitops.plan.systems.webserver.response.InternalErrorResponse; @@ -246,23 +247,35 @@ public class BukkitInformationManager extends InformationManager { @Override public boolean attemptConnection() { - Log.info("Attempting Bungee Connection.. (" + webServerAddress + ")"); - PingWebAPI api = getWebAPI().getAPI(PingWebAPI.class); + WebServer webServer = plugin.getWebServer(); + boolean webServerIsEnabled = webServer.isEnabled(); + boolean previousState = usingAnotherWebServer; + try { - api.sendRequest(webServerAddress); - getWebAPI().getAPI(PostOriginalBukkitSettingsWebAPI.class).sendRequest(webServerAddress); - Log.info("Bungee Connection OK"); - plugin.getServerInfoManager().resetConnectionFails(); - usingAnotherWebServer = true; - return true; - } catch (WebAPIConnectionFailException e) { - plugin.getServerInfoManager().markConnectionFail(); - } catch (WebAPIException e) { - Log.toLog(this.getClass().getName(), e); + Log.info("Attempting Bungee Connection.. (" + webServerAddress + ")"); + PingWebAPI api = getWebAPI().getAPI(PingWebAPI.class); + try { + api.sendRequest(webServerAddress); + getWebAPI().getAPI(PostOriginalBukkitSettingsWebAPI.class).sendRequest(webServerAddress); + Log.info("Bungee Connection OK"); + plugin.getServerInfoManager().resetConnectionFails(); + usingAnotherWebServer = true; + return true; + } catch (WebAPIConnectionFailException e) { + plugin.getServerInfoManager().markConnectionFail(); + } catch (WebAPIException e) { + Log.toLog(this.getClass().getName(), e); + } + Log.info("Bungee Connection Failed."); + usingAnotherWebServer = false; + return false; + } finally { + boolean changedState = previousState != usingAnotherWebServer; + if (webServerIsEnabled && changedState) { + webServer.stop(); + webServer.initServer(); + } } - Log.info("Bungee Connection Failed."); - usingAnotherWebServer = false; - return false; } @Override