Tweak network message logic, consolidate timeout handling

This commit is contained in:
William committed 2022-11-23 00:26:47 +00:00
1 parent 9a34ecdee6
commit b4e95b13d0
7 files changed
+116 -75

No files matched your search

@@ -223,13 +223,14 @@ public class Teleport {
MessagePayload.withPosition(target),
Message.RelayType.MESSAGE,
plugin.getSettings().clusterId))
.orTimeout(3, TimeUnit.SECONDS)
.exceptionally(throwable -> null)
.thenApply(result -> {
if (result == null || result.payload.resultState == null) {
return TeleportResult.FAILED_TELEPORTER_NOT_RESOLVED;
if (result.isPresent()) {
final Message reply = result.get();
if (reply.payload.resultState != null) {
return reply.payload.resultState;
}
}
return result.payload.resultState;
return TeleportResult.FAILED_TELEPORTER_NOT_RESOLVED;
});
}
@@ -12,7 +12,6 @@ import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
/**
@@ -237,7 +236,7 @@ public class TeleportBuilder {
if (plugin.getSettings().crossServer) {
return plugin.getNetworkMessenger()
.findPlayer(executor, playerName)
.thenApply(foundPlayer -> {
.thenApplyAsync(foundPlayer -> {
if (foundPlayer.isEmpty()) {
return Optional.empty();
}
@@ -245,9 +244,7 @@ public class TeleportBuilder {
.sendMessage(executor, new Message(Message.MessageType.POSITION_REQUEST,
executor.username, playerName, MessagePayload.empty(),
Message.RelayType.MESSAGE, plugin.getSettings().clusterId))
.orTimeout(3, TimeUnit.SECONDS)
.exceptionally(throwable -> null)
.thenApply(reply -> Optional.ofNullable(reply == null ? null : reply.payload.position)).join();
.thenApply(reply -> reply.map(message -> message.payload.position)).join();
});
}
return CompletableFuture.supplyAsync(Optional::empty);