More work on ConnectionSystem

This commit is contained in:
Rsl1122 2018-01-22 17:54:08 +02:00
parent 56717a8947
commit 334451372b
4 changed files with 43 additions and 9 deletions

View File

@ -50,10 +50,9 @@ public class DevCommand extends SubCommand {
break; break;
case "web": case "web":
ConnectionSystem connectionSystem = ConnectionSystem.getInstance(); ConnectionSystem connectionSystem = ConnectionSystem.getInstance();
Optional<String> bungeeConnectionAddress = connectionSystem.getMainAddress(); String accessAddress = connectionSystem.getMainAddress();
String accessAddress = plugin.getWebServer().getAccessAddress(); sender.sendMessage((connectionSystem.isServerAvailable())
sender.sendMessage((connectionSystem.isServerAvailable() && bungeeConnectionAddress.isPresent()) ? "Bungee: " + accessAddress : "Local: " + accessAddress);
? "Bungee: " + bungeeConnectionAddress.get() : "Local: " + accessAddress);
break; break;
default: default:
break; break;

View File

@ -91,12 +91,13 @@ public class BukkitConnectionSystem extends ConnectionSystem {
@Override @Override
public boolean isServerAvailable() { public boolean isServerAvailable() {
return false; return ConnectionLog.hasConnectionSucceeded(mainServer);
} }
@Override @Override
public Optional<String> getMainAddress() { public String getMainAddress() {
return Optional.empty(); return isServerAvailable() ? mainServer.getWebAddress() : ServerInfo.getServer().getWebAddress();
} }
@Override @Override

View File

@ -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.request.InfoRequest;
import com.djrapitops.plan.system.info.server.Server; import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.utilities.MiscUtils; import com.djrapitops.plan.utilities.MiscUtils;
import com.djrapitops.plugin.utilities.Verify;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -36,6 +37,40 @@ public class ConnectionLog {
log.put(toServer, requestMap); log.put(toServer, requestMap);
} }
public static boolean isConnectionPlausible(Server server) {
if (server == null) {
return false;
}
Map<String, Entry> 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<String, Entry> serverLog = getInstance().getLog().get(server);
if (Verify.isEmpty(serverLog)) {
return false;
}
return hasConnectionSucceeded(serverLog);
}
private static boolean hasConnectionSucceeded(Map<String, Entry> serverLog) {
for (Entry entry : serverLog.values()) {
if (entry.responseCode == 200) {
return true;
}
}
return false;
}
private static ConnectionLog getInstance() { private static ConnectionLog getInstance() {
return ConnectionSystem.getInstance().getConnectionLog(); return ConnectionSystem.getInstance().getConnectionLog();
} }

View File

@ -15,7 +15,6 @@ import com.djrapitops.plan.utilities.NullCheck;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
/** /**
@ -82,5 +81,5 @@ public abstract class ConnectionSystem implements SubSystem {
public abstract boolean isServerAvailable(); public abstract boolean isServerAvailable();
public abstract Optional<String> getMainAddress(); public abstract String getMainAddress();
} }