Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
merged 4 commits into from
Feb 5, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -31,7 +32,8 @@ public void run(final Server server, final CommandSource sender, final String co

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"));
Expand All @@ -44,6 +46,17 @@ public void run(final Server server, final CommandSource sender, final String co
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);

Expand All @@ -63,7 +76,7 @@ public void run(final Server server, final CommandSource sender, final String co
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);
Expand All @@ -72,10 +85,8 @@ public void run(final Server server, final CommandSource sender, final String co
}
});
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);
}
}
Expand Down