diff --git a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java index 13cfeff48..15a2ef450 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/ISettings.java @@ -345,7 +345,7 @@ public interface ISettings extends IConf { boolean isConfirmCommandEnabledByDefault(String commandName); - boolean isTeleportBackWhenFreedFromJail(); + TeleportWhenFreePolicy getTeleportWhenFreePolicy(); boolean isJailOnlineTime(); @@ -385,4 +385,10 @@ public interface ISettings extends IConf { DROP } + enum TeleportWhenFreePolicy { + SPAWN, + BACK, + OFF + } + } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index 4efe62276..da2591d52 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -122,7 +122,7 @@ public class Settings implements net.ess3.api.ISettings { private NumberFormat currencyFormat; private List unprotectedSigns = Collections.emptyList(); private List defaultEnabledConfirmCommands; - private boolean teleportBackWhenFreedFromJail; + private TeleportWhenFreePolicy teleportWhenFreePolicy; private boolean isCompassTowardsHomePerm; private boolean isAllowWorldInBroadcastworld; private String itemDbType; // #EasterEgg - admins can manually switch items provider if they want @@ -724,7 +724,7 @@ public class Settings implements net.ess3.api.ISettings { currencyFormat = _getCurrencyFormat(); unprotectedSigns = _getUnprotectedSign(); defaultEnabledConfirmCommands = _getDefaultEnabledConfirmCommands(); - teleportBackWhenFreedFromJail = _isTeleportBackWhenFreedFromJail(); + teleportWhenFreePolicy = _getTeleportWhenFreePolicy(); isCompassTowardsHomePerm = _isCompassTowardsHomePerm(); isAllowWorldInBroadcastworld = _isAllowWorldInBroadcastworld(); itemDbType = _getItemDbType(); @@ -1703,13 +1703,27 @@ public class Settings implements net.ess3.api.ISettings { return getDefaultEnabledConfirmCommands().contains(commandName.toLowerCase()); } - private boolean _isTeleportBackWhenFreedFromJail() { - return config.getBoolean("teleport-back-when-freed-from-jail", true); + private TeleportWhenFreePolicy _getTeleportWhenFreePolicy() { + if (config.hasProperty("teleport-back-when-freed-from-jail")) { + return config.getBoolean("teleport-back-when-freed-from-jail", true) ? TeleportWhenFreePolicy.BACK : TeleportWhenFreePolicy.OFF; + } + + if (config.hasProperty("teleport-when-freed")) { + // snakeyaml more like cursedyaml + final String value = config.getString("teleport-when-freed", "back").replace("false", "off"); + try { + return TeleportWhenFreePolicy.valueOf(value.toUpperCase(Locale.ROOT)); + } catch (IllegalArgumentException e) { + throw new RuntimeException("Invalid value \"" + value + "\" for config option \"teleport-when-freed\"!", e); + } + } + + return TeleportWhenFreePolicy.BACK; } @Override - public boolean isTeleportBackWhenFreedFromJail() { - return teleportBackWhenFreedFromJail; + public TeleportWhenFreePolicy getTeleportWhenFreePolicy() { + return teleportWhenFreePolicy; } @Override diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 9f8bc1b4a..ee59394eb 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -649,13 +649,15 @@ public class User extends UserData implements Comparable, IMessageRecipien setJailed(false); sendMessage(tl("haveBeenReleased")); setJail(null); - if (ess.getSettings().isTeleportBackWhenFreedFromJail()) { + if (ess.getSettings().getTeleportWhenFreePolicy() == ISettings.TeleportWhenFreePolicy.BACK) { final CompletableFuture future = new CompletableFuture<>(); getAsyncTeleport().back(future); future.exceptionally(e -> { getAsyncTeleport().respawn(null, TeleportCause.PLUGIN, new CompletableFuture<>()); return false; }); + } else if (ess.getSettings().getTeleportWhenFreePolicy() == ISettings.TeleportWhenFreePolicy.SPAWN) { + getAsyncTeleport().respawn(null, TeleportCause.PLUGIN, new CompletableFuture<>()); } return true; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtogglejail.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtogglejail.java index 815082640..93a7128f1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtogglejail.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtogglejail.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.ISettings; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.EnumUtil; @@ -122,19 +123,23 @@ public class Commandtogglejail extends EssentialsCommand { player.setJailTimeout(0); player.sendMessage(tl("jailReleasedPlayerNotify")); player.setJail(null); - if (player.getBase().isOnline() && ess.getSettings().isTeleportBackWhenFreedFromJail()) { + if (player.getBase().isOnline()) { final CompletableFuture future = getNewExceptionFuture(sender, commandLabel); - player.getAsyncTeleport().back(future); future.thenAccept(success -> { if (success) { 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; - }); + if (ess.getSettings().getTeleportWhenFreePolicy() == ISettings.TeleportWhenFreePolicy.BACK) { + player.getAsyncTeleport().back(future); + future.exceptionally(e -> { + player.getAsyncTeleport().respawn(null, PlayerTeleportEvent.TeleportCause.PLUGIN, new CompletableFuture<>()); + sender.sendMessage(tl("jailReleased", player.getName())); + return false; + }); + } else if (ess.getSettings().getTeleportWhenFreePolicy() == ISettings.TeleportWhenFreePolicy.SPAWN) { + player.getAsyncTeleport().respawn(null, PlayerTeleportEvent.TeleportCause.PLUGIN, future); + } return; } sender.sendMessage(tl("jailReleased", player.getName())); diff --git a/Essentials/src/main/resources/config.yml b/Essentials/src/main/resources/config.yml index c9b01966b..555e9646c 100644 --- a/Essentials/src/main/resources/config.yml +++ b/Essentials/src/main/resources/config.yml @@ -644,8 +644,10 @@ default-enabled-confirm-commands: #- pay #- clearinventory -# Whether or not to teleport a player back to their previous position after they have been freed from jail. -teleport-back-when-freed-from-jail: true +# Where should Essentials teleport players when they are freed from jail? +# You can set to "back" to have them teleported to where they were before they were jailed, "spawn" to have them +# teleport to spawn, or "off" to not have them teleport. +teleport-when-freed: back # Whether or not jail time should only be counted while the user is online. # If true, a jailed player's time will only decrement when they are online.