mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-28 12:07:35 +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;
|
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;
|
||||||
|
@ -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
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user