From ee5f4b9b422285243ea231a670903e0e601d21ac Mon Sep 17 00:00:00 2001 From: Frank van der Heijden <22407829+FrankHeijden@users.noreply.github.com> Date: Sat, 27 Feb 2021 17:19:28 +0100 Subject: [PATCH] Fix some futures in AsyncTeleport never completing (#4016) Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> --- .../main/java/com/earth2me/essentials/AsyncTeleport.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java b/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java index dd1c954e1..7982e9ff4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java +++ b/Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java @@ -160,6 +160,7 @@ public class AsyncTeleport implements IAsyncTeleport { final PreTeleportEvent event = new PreTeleportEvent(teleportee, cause, target); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { + future.complete(false); return; } teleportee.setLastLocation(); @@ -183,7 +184,7 @@ public class AsyncTeleport implements IAsyncTeleport { targetLoc.setX(LocationUtil.getXInsideWorldBorder(targetLoc.getWorld(), targetLoc.getBlockX())); 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; if (LocationUtil.isBlockUnsafeForUser(teleportee, chunk.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) { if (ess.getSettings().isTeleportSafetyEnabled()) { @@ -216,6 +217,9 @@ public class AsyncTeleport implements IAsyncTeleport { } } future.complete(true); + }).exceptionally(th -> { + future.completeExceptionally(th); + return null; }); } @@ -398,6 +402,9 @@ public class AsyncTeleport implements IAsyncTeleport { ess.getServer().getPluginManager().callEvent(pre); nowAsync(teleportee, new LocationTarget(pre.getRespawnLocation()), cause, future); } + }).exceptionally(th -> { + future.completeExceptionally(th); + return null; }); }