Fix some futures in AsyncTeleport never completing (#4016)

Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
This commit is contained in:
Frank van der Heijden 2021-02-27 17:19:28 +01:00 committed by GitHub
parent e5db842dd6
commit ee5f4b9b42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -160,6 +160,7 @@ public class AsyncTeleport implements IAsyncTeleport {
final PreTeleportEvent event = new PreTeleportEvent(teleportee, cause, target); final PreTeleportEvent event = new PreTeleportEvent(teleportee, cause, target);
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { if (event.isCancelled()) {
future.complete(false);
return; return;
} }
teleportee.setLastLocation(); teleportee.setLastLocation();
@ -183,7 +184,7 @@ public class AsyncTeleport implements IAsyncTeleport {
targetLoc.setX(LocationUtil.getXInsideWorldBorder(targetLoc.getWorld(), targetLoc.getBlockX())); targetLoc.setX(LocationUtil.getXInsideWorldBorder(targetLoc.getWorld(), targetLoc.getBlockX()));
targetLoc.setZ(LocationUtil.getZInsideWorldBorder(targetLoc.getWorld(), targetLoc.getBlockZ())); targetLoc.setZ(LocationUtil.getZInsideWorldBorder(targetLoc.getWorld(), targetLoc.getBlockZ()));
} }
PaperLib.getChunkAtAsync(targetLoc).thenAccept(chunk -> { PaperLib.getChunkAtAsync(targetLoc.getWorld(), targetLoc.getBlockX() >> 4, targetLoc.getBlockZ() >> 4, true, true).thenAccept(chunk -> {
Location loc = targetLoc; Location loc = targetLoc;
if (LocationUtil.isBlockUnsafeForUser(teleportee, chunk.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) { if (LocationUtil.isBlockUnsafeForUser(teleportee, chunk.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
if (ess.getSettings().isTeleportSafetyEnabled()) { if (ess.getSettings().isTeleportSafetyEnabled()) {
@ -216,6 +217,9 @@ public class AsyncTeleport implements IAsyncTeleport {
} }
} }
future.complete(true); future.complete(true);
}).exceptionally(th -> {
future.completeExceptionally(th);
return null;
}); });
} }
@ -398,6 +402,9 @@ public class AsyncTeleport implements IAsyncTeleport {
ess.getServer().getPluginManager().callEvent(pre); ess.getServer().getPluginManager().callEvent(pre);
nowAsync(teleportee, new LocationTarget(pre.getRespawnLocation()), cause, future); nowAsync(teleportee, new LocationTarget(pre.getRespawnLocation()), cause, future);
} }
}).exceptionally(th -> {
future.completeExceptionally(th);
return null;
}); });
} }