mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-06 11:24:39 +08:00
Infer jail name when the server only has one jail configured (#3911)
Closes #1122.
This commit is contained in:
parent
fccf796eeb
commit
4e7f1377bf
@ -4,6 +4,7 @@ import com.earth2me.essentials.CommandSource;
|
|||||||
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;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import net.ess3.api.events.JailStatusChangeEvent;
|
import net.ess3.api.events.JailStatusChangeEvent;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.Statistic;
|
import org.bukkit.Statistic;
|
||||||
@ -31,7 +32,8 @@ public class Commandtogglejail extends EssentialsCommand {
|
|||||||
|
|
||||||
final User player = getPlayer(server, args, 0, true, true);
|
final User player = getPlayer(server, args, 0, true, true);
|
||||||
|
|
||||||
if (args.length >= 2 && !player.isJailed()) {
|
mainCommand:
|
||||||
|
if (!player.isJailed()) {
|
||||||
if (!player.getBase().isOnline()) {
|
if (!player.getBase().isOnline()) {
|
||||||
if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.togglejail.offline")) {
|
if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.togglejail.offline")) {
|
||||||
sender.sendMessage(tl("mayNotJailOffline"));
|
sender.sendMessage(tl("mayNotJailOffline"));
|
||||||
@ -44,6 +46,17 @@ public class Commandtogglejail extends EssentialsCommand {
|
|||||||
return;
|
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);
|
final JailStatusChangeEvent event = new JailStatusChangeEvent(player, sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null, true);
|
||||||
ess.getServer().getPluginManager().callEvent(event);
|
ess.getServer().getPluginManager().callEvent(event);
|
||||||
|
|
||||||
@ -63,7 +76,7 @@ public class Commandtogglejail extends EssentialsCommand {
|
|||||||
player.setJailed(true);
|
player.setJailed(true);
|
||||||
player.sendMessage(tl("userJailed"));
|
player.sendMessage(tl("userJailed"));
|
||||||
player.setJail(null);
|
player.setJail(null);
|
||||||
player.setJail(args[1]);
|
player.setJail(jailName);
|
||||||
if (args.length > 2) {
|
if (args.length > 2) {
|
||||||
player.setJailTimeout(timeDiff);
|
player.setJailTimeout(timeDiff);
|
||||||
player.setOnlineJailedTime(ess.getSettings().isJailOnlineTime() ? ((player.getBase().getStatistic(PLAY_ONE_TICK)) + (timeDiff / 50)) : 0);
|
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()) {
|
if (player.getBase().isOnline()) {
|
||||||
ess.getJails().sendToJail(player, args[1], future);
|
ess.getJails().sendToJail(player, jailName, future);
|
||||||
} else {
|
} else {
|
||||||
// Check if jail exists
|
|
||||||
ess.getJails().getJail(args[1]);
|
|
||||||
future.complete(true);
|
future.complete(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user