From 334451372b8ec37af4f4b574e66fe24d28c2dd26 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 22 Jan 2018 17:54:08 +0200 Subject: [PATCH] More work on ConnectionSystem --- .../plan/command/commands/DevCommand.java | 7 ++-- .../connection/BukkitConnectionSystem.java | 7 ++-- .../system/info/connection/ConnectionLog.java | 35 +++++++++++++++++++ .../info/connection/ConnectionSystem.java | 3 +- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/command/commands/DevCommand.java b/Plan/src/main/java/com/djrapitops/plan/command/commands/DevCommand.java index e7f5eb3a2..2b4da7b95 100644 --- a/Plan/src/main/java/com/djrapitops/plan/command/commands/DevCommand.java +++ b/Plan/src/main/java/com/djrapitops/plan/command/commands/DevCommand.java @@ -50,10 +50,9 @@ public class DevCommand extends SubCommand { break; case "web": ConnectionSystem connectionSystem = ConnectionSystem.getInstance(); - Optional bungeeConnectionAddress = connectionSystem.getMainAddress(); - String accessAddress = plugin.getWebServer().getAccessAddress(); - sender.sendMessage((connectionSystem.isServerAvailable() && bungeeConnectionAddress.isPresent()) - ? "Bungee: " + bungeeConnectionAddress.get() : "Local: " + accessAddress); + String accessAddress = connectionSystem.getMainAddress(); + sender.sendMessage((connectionSystem.isServerAvailable()) + ? "Bungee: " + accessAddress : "Local: " + accessAddress); break; default: break; diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java index fb155ce3f..891c6414f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BukkitConnectionSystem.java @@ -91,12 +91,13 @@ public class BukkitConnectionSystem extends ConnectionSystem { @Override public boolean isServerAvailable() { - return false; + return ConnectionLog.hasConnectionSucceeded(mainServer); } @Override - public Optional getMainAddress() { - return Optional.empty(); + public String getMainAddress() { + return isServerAvailable() ? mainServer.getWebAddress() : ServerInfo.getServer().getWebAddress(); + } @Override diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionLog.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionLog.java index aaaae7085..366811aab 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionLog.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionLog.java @@ -7,6 +7,7 @@ package com.djrapitops.plan.system.info.connection; import com.djrapitops.plan.system.info.request.InfoRequest; import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.utilities.MiscUtils; +import com.djrapitops.plugin.utilities.Verify; import java.util.HashMap; import java.util.Map; @@ -36,6 +37,40 @@ public class ConnectionLog { log.put(toServer, requestMap); } + public static boolean isConnectionPlausible(Server server) { + if (server == null) { + return false; + } + + Map serverLog = getInstance().getLog().get(server); + if (Verify.isEmpty(serverLog)) { + return true; + } + + return hasConnectionSucceeded(serverLog); + } + + public static boolean hasConnectionSucceeded(Server server) { + if (server == null) { + return false; + } + Map serverLog = getInstance().getLog().get(server); + if (Verify.isEmpty(serverLog)) { + return false; + } + + return hasConnectionSucceeded(serverLog); + } + + private static boolean hasConnectionSucceeded(Map serverLog) { + for (Entry entry : serverLog.values()) { + if (entry.responseCode == 200) { + return true; + } + } + return false; + } + private static ConnectionLog getInstance() { return ConnectionSystem.getInstance().getConnectionLog(); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java index bca322dd1..797d3b027 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java @@ -15,7 +15,6 @@ import com.djrapitops.plan.utilities.NullCheck; import java.util.HashMap; import java.util.Map; -import java.util.Optional; import java.util.UUID; /** @@ -82,5 +81,5 @@ public abstract class ConnectionSystem implements SubSystem { public abstract boolean isServerAvailable(); - public abstract Optional getMainAddress(); + public abstract String getMainAddress(); } \ No newline at end of file