Properly handle jail respawn in togglejail (#3522)

This commit is contained in:
Josh Roy 2020-07-21 19:22:20 -04:00 committed by GitHub
parent e34984513d
commit 9aec89f381
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -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<Boolean> 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()));