Fixed #292 & Bypassed #295

This commit is contained in:
Rsl1122 2017-09-28 19:29:49 +03:00
parent d57f159486
commit 15cc6092d1
3 changed files with 38 additions and 22 deletions

View File

@ -50,10 +50,8 @@ public class PlanCommand extends TreeCommand<Plan> {
RegisterCommand registerCommand = new RegisterCommand(plugin); RegisterCommand registerCommand = new RegisterCommand(plugin);
commands.add(registerCommand); commands.add(registerCommand);
commands.add(new WebUserCommand(plugin, registerCommand)); commands.add(new WebUserCommand(plugin, registerCommand));
if (plugin.getInfoManager().isUsingAnotherWebServer()) { commands.add(new NetworkCommand(plugin));
commands.add(new NetworkCommand()); commands.add(new ListServersCommand(plugin));
commands.add(new ListServersCommand(plugin));
}
if (Settings.DEV_MODE.isTrue()) { if (Settings.DEV_MODE.isTrue()) {
commands.add(new DevCommand(plugin)); commands.add(new DevCommand(plugin));

View File

@ -19,17 +19,22 @@ import main.java.com.djrapitops.plan.locale.Msg;
*/ */
public class NetworkCommand extends SubCommand { public class NetworkCommand extends SubCommand {
private final Plan plugin;
/** /**
* Class Constructor. * Class Constructor.
*/ */
public NetworkCommand() { public NetworkCommand(Plan plugin) {
super("network, n, netw", CommandType.CONSOLE, Permissions.ANALYZE.getPermission(), Locale.get(Msg.CMD_USG_LIST).toString(), ""); super("network, n, netw", CommandType.CONSOLE, Permissions.ANALYZE.getPermission(), Locale.get(Msg.CMD_USG_LIST).toString(), "");
this.plugin = plugin;
} }
@Override @Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) { public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (plugin.getInfoManager().isUsingAnotherWebServer()) {
sender.sendMessage("§cNot using Bungee WebServer!");
return true;
}
sendNetworkMsg(sender); sendNetworkMsg(sender);
return true; return true;
} }

View File

@ -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.info.parsing.InspectPageParser;
import main.java.com.djrapitops.plan.systems.processing.Processor; 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.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.AnalysisPageResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse; import main.java.com.djrapitops.plan.systems.webserver.response.InspectPageResponse;
import main.java.com.djrapitops.plan.systems.webserver.response.InternalErrorResponse; import main.java.com.djrapitops.plan.systems.webserver.response.InternalErrorResponse;
@ -246,23 +247,35 @@ public class BukkitInformationManager extends InformationManager {
@Override @Override
public boolean attemptConnection() { public boolean attemptConnection() {
Log.info("Attempting Bungee Connection.. (" + webServerAddress + ")"); WebServer webServer = plugin.getWebServer();
PingWebAPI api = getWebAPI().getAPI(PingWebAPI.class); boolean webServerIsEnabled = webServer.isEnabled();
boolean previousState = usingAnotherWebServer;
try { try {
api.sendRequest(webServerAddress); Log.info("Attempting Bungee Connection.. (" + webServerAddress + ")");
getWebAPI().getAPI(PostOriginalBukkitSettingsWebAPI.class).sendRequest(webServerAddress); PingWebAPI api = getWebAPI().getAPI(PingWebAPI.class);
Log.info("Bungee Connection OK"); try {
plugin.getServerInfoManager().resetConnectionFails(); api.sendRequest(webServerAddress);
usingAnotherWebServer = true; getWebAPI().getAPI(PostOriginalBukkitSettingsWebAPI.class).sendRequest(webServerAddress);
return true; Log.info("Bungee Connection OK");
} catch (WebAPIConnectionFailException e) { plugin.getServerInfoManager().resetConnectionFails();
plugin.getServerInfoManager().markConnectionFail(); usingAnotherWebServer = true;
} catch (WebAPIException e) { return true;
Log.toLog(this.getClass().getName(), e); } 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 @Override