mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 15:08:18 +01:00
Add config option to respawn jailed players to spawn (#4132)
This commit is contained in:
parent
3abddd6f84
commit
54c70581a2
@ -345,7 +345,7 @@ public interface ISettings extends IConf {
|
|||||||
|
|
||||||
boolean isConfirmCommandEnabledByDefault(String commandName);
|
boolean isConfirmCommandEnabledByDefault(String commandName);
|
||||||
|
|
||||||
boolean isTeleportBackWhenFreedFromJail();
|
TeleportWhenFreePolicy getTeleportWhenFreePolicy();
|
||||||
|
|
||||||
boolean isJailOnlineTime();
|
boolean isJailOnlineTime();
|
||||||
|
|
||||||
@ -385,4 +385,10 @@ public interface ISettings extends IConf {
|
|||||||
DROP
|
DROP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum TeleportWhenFreePolicy {
|
||||||
|
SPAWN,
|
||||||
|
BACK,
|
||||||
|
OFF
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ public class Settings implements net.ess3.api.ISettings {
|
|||||||
private NumberFormat currencyFormat;
|
private NumberFormat currencyFormat;
|
||||||
private List<EssentialsSign> unprotectedSigns = Collections.emptyList();
|
private List<EssentialsSign> unprotectedSigns = Collections.emptyList();
|
||||||
private List<String> defaultEnabledConfirmCommands;
|
private List<String> defaultEnabledConfirmCommands;
|
||||||
private boolean teleportBackWhenFreedFromJail;
|
private TeleportWhenFreePolicy teleportWhenFreePolicy;
|
||||||
private boolean isCompassTowardsHomePerm;
|
private boolean isCompassTowardsHomePerm;
|
||||||
private boolean isAllowWorldInBroadcastworld;
|
private boolean isAllowWorldInBroadcastworld;
|
||||||
private String itemDbType; // #EasterEgg - admins can manually switch items provider if they want
|
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();
|
currencyFormat = _getCurrencyFormat();
|
||||||
unprotectedSigns = _getUnprotectedSign();
|
unprotectedSigns = _getUnprotectedSign();
|
||||||
defaultEnabledConfirmCommands = _getDefaultEnabledConfirmCommands();
|
defaultEnabledConfirmCommands = _getDefaultEnabledConfirmCommands();
|
||||||
teleportBackWhenFreedFromJail = _isTeleportBackWhenFreedFromJail();
|
teleportWhenFreePolicy = _getTeleportWhenFreePolicy();
|
||||||
isCompassTowardsHomePerm = _isCompassTowardsHomePerm();
|
isCompassTowardsHomePerm = _isCompassTowardsHomePerm();
|
||||||
isAllowWorldInBroadcastworld = _isAllowWorldInBroadcastworld();
|
isAllowWorldInBroadcastworld = _isAllowWorldInBroadcastworld();
|
||||||
itemDbType = _getItemDbType();
|
itemDbType = _getItemDbType();
|
||||||
@ -1703,13 +1703,27 @@ public class Settings implements net.ess3.api.ISettings {
|
|||||||
return getDefaultEnabledConfirmCommands().contains(commandName.toLowerCase());
|
return getDefaultEnabledConfirmCommands().contains(commandName.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean _isTeleportBackWhenFreedFromJail() {
|
private TeleportWhenFreePolicy _getTeleportWhenFreePolicy() {
|
||||||
return config.getBoolean("teleport-back-when-freed-from-jail", true);
|
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
|
@Override
|
||||||
public boolean isTeleportBackWhenFreedFromJail() {
|
public TeleportWhenFreePolicy getTeleportWhenFreePolicy() {
|
||||||
return teleportBackWhenFreedFromJail;
|
return teleportWhenFreePolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -649,13 +649,15 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
|||||||
setJailed(false);
|
setJailed(false);
|
||||||
sendMessage(tl("haveBeenReleased"));
|
sendMessage(tl("haveBeenReleased"));
|
||||||
setJail(null);
|
setJail(null);
|
||||||
if (ess.getSettings().isTeleportBackWhenFreedFromJail()) {
|
if (ess.getSettings().getTeleportWhenFreePolicy() == ISettings.TeleportWhenFreePolicy.BACK) {
|
||||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||||
getAsyncTeleport().back(future);
|
getAsyncTeleport().back(future);
|
||||||
future.exceptionally(e -> {
|
future.exceptionally(e -> {
|
||||||
getAsyncTeleport().respawn(null, TeleportCause.PLUGIN, new CompletableFuture<>());
|
getAsyncTeleport().respawn(null, TeleportCause.PLUGIN, new CompletableFuture<>());
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
} else if (ess.getSettings().getTeleportWhenFreePolicy() == ISettings.TeleportWhenFreePolicy.SPAWN) {
|
||||||
|
getAsyncTeleport().respawn(null, TeleportCause.PLUGIN, new CompletableFuture<>());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
import com.earth2me.essentials.CommandSource;
|
import com.earth2me.essentials.CommandSource;
|
||||||
|
import com.earth2me.essentials.ISettings;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.utils.DateUtil;
|
import com.earth2me.essentials.utils.DateUtil;
|
||||||
import com.earth2me.essentials.utils.EnumUtil;
|
import com.earth2me.essentials.utils.EnumUtil;
|
||||||
@ -122,19 +123,23 @@ public class Commandtogglejail extends EssentialsCommand {
|
|||||||
player.setJailTimeout(0);
|
player.setJailTimeout(0);
|
||||||
player.sendMessage(tl("jailReleasedPlayerNotify"));
|
player.sendMessage(tl("jailReleasedPlayerNotify"));
|
||||||
player.setJail(null);
|
player.setJail(null);
|
||||||
if (player.getBase().isOnline() && ess.getSettings().isTeleportBackWhenFreedFromJail()) {
|
if (player.getBase().isOnline()) {
|
||||||
final CompletableFuture<Boolean> future = getNewExceptionFuture(sender, commandLabel);
|
final CompletableFuture<Boolean> future = getNewExceptionFuture(sender, commandLabel);
|
||||||
player.getAsyncTeleport().back(future);
|
|
||||||
future.thenAccept(success -> {
|
future.thenAccept(success -> {
|
||||||
if (success) {
|
if (success) {
|
||||||
sender.sendMessage(tl("jailReleased", player.getName()));
|
sender.sendMessage(tl("jailReleased", player.getName()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
future.exceptionally(e -> {
|
if (ess.getSettings().getTeleportWhenFreePolicy() == ISettings.TeleportWhenFreePolicy.BACK) {
|
||||||
player.getAsyncTeleport().respawn(null, PlayerTeleportEvent.TeleportCause.PLUGIN, new CompletableFuture<>());
|
player.getAsyncTeleport().back(future);
|
||||||
sender.sendMessage(tl("jailReleased", player.getName()));
|
future.exceptionally(e -> {
|
||||||
return false;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
sender.sendMessage(tl("jailReleased", player.getName()));
|
sender.sendMessage(tl("jailReleased", player.getName()));
|
||||||
|
@ -644,8 +644,10 @@ default-enabled-confirm-commands:
|
|||||||
#- pay
|
#- pay
|
||||||
#- clearinventory
|
#- clearinventory
|
||||||
|
|
||||||
# Whether or not to teleport a player back to their previous position after they have been freed from jail.
|
# Where should Essentials teleport players when they are freed from jail?
|
||||||
teleport-back-when-freed-from-jail: true
|
# 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.
|
# 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.
|
# If true, a jailed player's time will only decrement when they are online.
|
||||||
|
Loading…
Reference in New Issue
Block a user