mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 19:47:49 +01:00
More work on ConnectionSystem
This commit is contained in:
parent
56717a8947
commit
334451372b
@ -50,10 +50,9 @@ public class DevCommand extends SubCommand {
|
||||
break;
|
||||
case "web":
|
||||
ConnectionSystem connectionSystem = ConnectionSystem.getInstance();
|
||||
Optional<String> 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;
|
||||
|
@ -91,12 +91,13 @@ public class BukkitConnectionSystem extends ConnectionSystem {
|
||||
|
||||
@Override
|
||||
public boolean isServerAvailable() {
|
||||
return false;
|
||||
return ConnectionLog.hasConnectionSucceeded(mainServer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getMainAddress() {
|
||||
return Optional.empty();
|
||||
public String getMainAddress() {
|
||||
return isServerAvailable() ? mainServer.getWebAddress() : ServerInfo.getServer().getWebAddress();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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<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() {
|
||||
return ConnectionSystem.getInstance().getConnectionLog();
|
||||
}
|
||||
|
@ -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<String> getMainAddress();
|
||||
public abstract String getMainAddress();
|
||||
}
|
Loading…
Reference in New Issue
Block a user