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
|
package com.earth2me.essentials.commands;
import com.earth2me.essentials.*;
import static com.earth2me.essentials.I18n._;
import java.util.*;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
public class Commandkit extends EssentialsCommand
{
public Commandkit()
{
super("kit");
}
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
final String kitList = Kit.listKits(ess, user);
user.sendMessage(kitList.length() > 0 ? _("kits", kitList) : _("noKits"));
throw new NoChargeException();
}
else if (args.length > 1 && user.isAuthorized("essentials.kit.others"))
{
final User userTo = getPlayer(server, args, 1, true);
final String kitName = Util.sanitizeString(args[0].toLowerCase(Locale.ENGLISH)).trim();
giveKit(userTo, user, kitName);
}
else
{
final String kitName = Util.sanitizeString(args[0].toLowerCase(Locale.ENGLISH)).trim();
giveKit(user, user, kitName);
}
}
@Override
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 2)
{
final String kitList = Kit.listKits(ess, null);
sender.sendMessage(kitList.length() > 0 ? _("kits", kitList) : _("noKits"));
throw new NoChargeException();
}
else
{
final User userTo = getPlayer(server, args, 1, true);
final String kitName = args[0].toLowerCase(Locale.ENGLISH);
final Map<String, Object> kit = ess.getSettings().getKit(kitName);
final List<String> items = Kit.getItems(userTo, kit);
Kit.expandItems(ess, userTo, items);
sender.sendMessage(_("kitGive", kitName));
}
}
private void giveKit(User userTo, User userFrom, String kitName) throws Exception
{
if (kitName.isEmpty())
{
throw new Exception(_("kitError2"));
}
final Map<String, Object> kit = ess.getSettings().getKit(kitName);
if (!userFrom.isAuthorized("essentials.kit." + kitName))
{
throw new Exception(_("noKitPermission", "essentials.kit." + kitName));
}
final List<String> items = Kit.getItems(userTo, kit);
Kit.checkTime(userFrom, kitName, kit);
final Trade charge = new Trade("kit-" + kitName, ess);
charge.isAffordableFor(userFrom);
Kit.expandItems(ess, userTo, items);
charge.charge(userFrom);
userTo.sendMessage(_("kitGive", kitName));
}
}
|