Fixed offline servers sometimes not being marked as offline on velocity

This commit is contained in:
ajgeiss0702
2022-10-20 13:48:31 -07:00
parent 11dcda49fd
commit d78c795288
4 changed files with 38 additions and 19 deletions
@@ -53,19 +53,12 @@ public class VelocityServer implements AdaptedServer {
if(debug) logger.info("[pinger] [" + getName() + "] sending ping");
serverPing.thenRunAsync(() -> {
System.out.println("thenRunAsync " + getName());
VelocityServerPing ping;
try {
ping = new VelocityServerPing(serverPing.get(), sent);
} catch (Throwable e) {
long lastOnline = lastSuccessfullPing == null ? 0 : lastSuccessfullPing.getFetchedTime();
offlineTime = (int) Math.min(sent - lastOnline, Integer.MAX_VALUE);
lastOffline = sent;
future.completeExceptionally(e);
lastPing = null;
if(debug) logger.info("[pinger] [" + getName() + "] offline:", e);
markOffline(debug, logger, future, sent, e);
return;
}
@@ -79,10 +72,24 @@ public class VelocityServer implements AdaptedServer {
future.complete(ping);
lastPing = ping;
}).exceptionally(e -> {
markOffline(debug, logger, future, sent, e);
return null;
});
return future;
}
private void markOffline(boolean debug, QueueLogger logger, CompletableFuture<AdaptedServerPing> future, long sent, Throwable e) {
long lastOnline = lastSuccessfullPing == null ? 0 : lastSuccessfullPing.getFetchedTime();
offlineTime = (int) Math.min(sent - lastOnline, Integer.MAX_VALUE);
lastOffline = sent;
future.completeExceptionally(e);
lastPing = null;
if(debug) logger.info("[pinger] [" + getName() + "] offline:", e);
}
@Override
public Optional<AdaptedServerPing> getLastPing() {
return Optional.ofNullable(lastPing);