blob: 13b72f92ce90cbc2e17e86bdaf9f85a60c95ac4c (
plain)
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
|
package net.ess3.commands;
import net.ess3.Console;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import net.ess3.permissions.Permissions;
import net.ess3.user.Ban;
import net.ess3.user.UserData;
import net.ess3.utils.DateUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Calendar;
public class Commandtempban extends EssentialsCommand
{
@Override
protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 2)
{
throw new NotEnoughArgumentsException();
}
final IUser user = ess.getUserMap().matchUser(args[0], true);
if (!user.isOnline())
{
if (Permissions.TEMPBAN_OFFLINE.isAuthorized(sender))
{
sender.sendMessage(_("tempbanExempt"));
return;
}
}
else
{
if (Permissions.TEMPBAN_EXEMPT.isAuthorized(user) && sender instanceof Player)
{
sender.sendMessage(_("tempbanExempt"));
return;
}
}
final String time = getFinalArg(args, 1);
final long banTimestamp = DateUtil.parseDateDiff(time, true);
final long max = ess.getSettings().getData().getCommands().getTempban().getMaxTempbanTime();
if(max != -1 && banTimestamp - Calendar.getInstance().getTimeInMillis() > max && !Permissions.TEMPBAN_UNLIMITED.isAuthorized(sender))
{
sender.sendMessage(_("tempbanOversized"));
return;
}
final String banReason = _("tempBanned", DateUtil.formatDateDiff(banTimestamp));
final Ban ban = new Ban();
final UserData userData = user.getData();
ban.setReason(banReason);
ban.setTimeout(banTimestamp);
userData.setBan(ban);
user.setBanned(true);
user.queueSave();
user.getPlayer().kickPlayer(banReason);
final String senderName = isUser(sender) ? getPlayer(sender).getDisplayName() : Console.NAME;
for (Player onlinePlayer : server.getOnlinePlayers())
{
final IUser player = ess.getUserMap().getUser(onlinePlayer);
if (Permissions.BAN_NOTIFY.isAuthorized(player))
{
onlinePlayer.sendMessage(_("playerBanned", senderName, user.getName(), banReason));
}
}
}
}
|