1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.OfflinePlayer;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Util;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class Commandtogglejail extends EssentialsCommand
{
public Commandtogglejail()
{
super("togglejail");
}
@Override
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
final User player = getPlayer(server, args, 0, true);
if (args.length >= 2 && !player.isJailed())
{
if (player.getBase() instanceof OfflinePlayer)
{
if (sender instanceof Player
&& !ess.getUser(sender).isAuthorized("essentials.togglejail.offline"))
{
sender.sendMessage(_("mayNotJail"));
return;
}
}
else
{
if (player.isAuthorized("essentials.jail.exempt"))
{
sender.sendMessage(_("mayNotJail"));
return;
}
}
if (!(player.getBase() instanceof OfflinePlayer))
{
ess.getJails().sendToJail(player, args[1]);
}
else
{
// Check if jail exists
ess.getJails().getJail(args[1]);
}
player.setJailed(true);
player.sendMessage(_("userJailed"));
player.setJail(null);
player.setJail(args[1]);
long timeDiff = 0;
if (args.length > 2)
{
final String time = getFinalArg(args, 2);
timeDiff = Util.parseDateDiff(time, true);
player.setJailTimeout(timeDiff);
}
sender.sendMessage((timeDiff > 0
? _("playerJailedFor", player.getName(), Util.formatDateDiff(timeDiff))
: _("playerJailed", player.getName())));
return;
}
if (args.length >= 2 && player.isJailed() && !args[1].equalsIgnoreCase(player.getJail()))
{
sender.sendMessage(_("jailAlreadyIncarcerated", player.getJail()));
return;
}
if (args.length >= 2 && player.isJailed() && args[1].equalsIgnoreCase(player.getJail()))
{
final String time = getFinalArg(args, 2);
final long timeDiff = Util.parseDateDiff(time, true);
player.setJailTimeout(timeDiff);
sender.sendMessage(_("jailSentenceExtended", Util.formatDateDiff(timeDiff)));
return;
}
if (args.length == 1 || (args.length == 2 && args[1].equalsIgnoreCase(player.getJail())))
{
if (!player.isJailed())
{
throw new NotEnoughArgumentsException();
}
player.setJailed(false);
player.setJailTimeout(0);
player.sendMessage(_("jailReleasedPlayerNotify"));
player.setJail(null);
if (!(player.getBase() instanceof OfflinePlayer))
{
player.getTeleport().back();
}
sender.sendMessage(_("jailReleased", player.getName()));
}
}
}
|