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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import java.util.List;
import java.util.Locale;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
public class Commandunlimited extends EssentialsCommand
{
public Commandunlimited()
{
super("unlimited");
}
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
if (args.length < 1)
{
throw new NotEnoughArgumentsException();
}
User target = user;
if (args.length > 1 && user.isAuthorized("essentials.unlimited.others"))
{
target = getPlayer(server, args, 1);
}
if (args[0].equalsIgnoreCase("list"))
{
final String list = getList(target);
user.sendMessage(list);
}
else if (args[0].equalsIgnoreCase("clear"))
{
final List<Integer> itemList = target.getUnlimited();
int index = 0;
while (itemList.size() > index)
{
final Integer item = itemList.get(index);
if (toggleUnlimited(user, target, item.toString()) == false)
{
index++;
}
}
}
else
{
toggleUnlimited(user, target, args[0]);
}
}
private String getList(final User target)
{
final StringBuilder output = new StringBuilder();
output.append(_("unlimitedItems")).append(" ");
boolean first = true;
final List<Integer> items = target.getUnlimited();
if (items.isEmpty())
{
output.append(_("none"));
}
for (Integer integer : items)
{
if (!first)
{
output.append(", ");
}
first = false;
final String matname = Material.getMaterial(integer).toString().toLowerCase(Locale.ENGLISH).replace("_", "");
output.append(matname);
}
return output.toString();
}
private Boolean toggleUnlimited(final User user, final User target, final String item) throws Exception
{
final ItemStack stack = ess.getItemDb().get(item, 1);
stack.setAmount(Math.min(stack.getType().getMaxStackSize(), 2));
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
if (ess.getSettings().permissionBasedItemSpawn()
&& (!user.isAuthorized("essentials.unlimited.item-all")
&& !user.isAuthorized("essentials.unlimited.item-" + itemname)
&& !user.isAuthorized("essentials.unlimited.item-" + stack.getTypeId())
&& !((stack.getType() == Material.WATER_BUCKET || stack.getType() == Material.LAVA_BUCKET)
&& user.isAuthorized("essentials.unlimited.item-bucket"))))
{
throw new Exception(_("unlimitedItemPermission", itemname));
}
String message = "disableUnlimited";
boolean enableUnlimited = false;
if (!target.hasUnlimited(stack))
{
message = "enableUnlimited";
enableUnlimited = true;
if (!InventoryWorkaround.containsItem(target.getInventory(), true, true, stack))
{
target.getInventory().addItem(stack);
}
}
if (user != target)
{
user.sendMessage(_(message, itemname, target.getDisplayName()));
}
target.sendMessage(_(message, itemname, target.getDisplayName()));
target.setUnlimited(stack, enableUnlimited);
return true;
}
}
|