From 9aec89f3815ec72c9db5bfda1b305a88436b3fd3 Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Tue, 21 Jul 2020 19:22:20 -0400 Subject: [PATCH] Properly handle jail respawn in togglejail (#3522) --- .../earth2me/essentials/commands/Commandtogglejail.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java index 85af0c1a3..8fbbb9282 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtogglejail.java @@ -5,6 +5,7 @@ import com.earth2me.essentials.User; import com.earth2me.essentials.utils.DateUtil; import net.ess3.api.events.JailStatusChangeEvent; import org.bukkit.Server; +import org.bukkit.event.player.PlayerTeleportEvent; import java.util.ArrayList; import java.util.Collections; @@ -101,7 +102,7 @@ public class Commandtogglejail extends EssentialsCommand { player.setJailTimeout(0); player.sendMessage(tl("jailReleasedPlayerNotify")); player.setJail(null); - if (player.getBase().isOnline()) { + if (player.getBase().isOnline() && ess.getSettings().isTeleportBackWhenFreedFromJail()) { CompletableFuture future = getNewExceptionFuture(sender, commandLabel); player.getAsyncTeleport().back(future); future.thenAccept(success -> { @@ -109,6 +110,11 @@ public class Commandtogglejail extends EssentialsCommand { sender.sendMessage(tl("jailReleased", player.getName())); } }); + future.exceptionally(e -> { + player.getAsyncTeleport().respawn(null, PlayerTeleportEvent.TeleportCause.PLUGIN, new CompletableFuture<>()); + sender.sendMessage(tl("jailReleased", player.getName())); + return false; + }); return; } sender.sendMessage(tl("jailReleased", player.getName()));