Infer jail name when the server only has one jail configured (#3911)

Closes #1122.
This commit is contained in:
Josh Roy 2021-02-05 14:39:20 -05:00 committed by GitHub
parent fccf796eeb
commit 4e7f1377bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.EnumUtil;
import com.google.common.collect.Iterables;
import net.ess3.api.events.JailStatusChangeEvent;
import org.bukkit.Server;
import org.bukkit.Statistic;
@ -31,7 +32,8 @@ public class Commandtogglejail extends EssentialsCommand {
final User player = getPlayer(server, args, 0, true, true);
if (args.length >= 2 && !player.isJailed()) {
mainCommand:
if (!player.isJailed()) {
if (!player.getBase().isOnline()) {
if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.togglejail.offline")) {
sender.sendMessage(tl("mayNotJailOffline"));
@ -44,6 +46,17 @@ public class Commandtogglejail extends EssentialsCommand {
return;
}
final String jailName;
if (args.length > 1) {
jailName = args[1];
} else if (ess.getJails().getCount() == 1) {
jailName = Iterables.get(ess.getJails().getList(), 0);
} else {
break mainCommand;
}
// Check if jail exists
ess.getJails().getJail(jailName);
final JailStatusChangeEvent event = new JailStatusChangeEvent(player, sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null, true);
ess.getServer().getPluginManager().callEvent(event);
@ -63,7 +76,7 @@ public class Commandtogglejail extends EssentialsCommand {
player.setJailed(true);
player.sendMessage(tl("userJailed"));
player.setJail(null);
player.setJail(args[1]);
player.setJail(jailName);
if (args.length > 2) {
player.setJailTimeout(timeDiff);
player.setOnlineJailedTime(ess.getSettings().isJailOnlineTime() ? ((player.getBase().getStatistic(PLAY_ONE_TICK)) + (timeDiff / 50)) : 0);
@ -72,10 +85,8 @@ public class Commandtogglejail extends EssentialsCommand {
}
});
if (player.getBase().isOnline()) {
ess.getJails().sendToJail(player, args[1], future);
ess.getJails().sendToJail(player, jailName, future);
} else {
// Check if jail exists
ess.getJails().getJail(args[1]);
future.complete(true);
}
}