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
|
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.Util;
import com.earth2me.essentials.api.IUser;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class Commandpowertool extends EssentialsCommand
{
@Override
protected void run(final IUser user, final String commandLabel, final String[] args) throws Exception
{
String command = getFinalArg(args, 0);
// check to see if this is a clear all command
if (command != null && command.equalsIgnoreCase("d:"))
{
user.acquireWriteLock();
user.getData().clearAllPowertools();
user.sendMessage(_("powerToolClearAll"));
return;
}
final ItemStack itemStack = user.getItemInHand();
if (itemStack == null || itemStack.getType() == Material.AIR)
{
throw new Exception(_("powerToolAir"));
}
final String itemName = itemStack.getType().toString().toLowerCase(Locale.ENGLISH).replaceAll("_", " ");
List<String> powertools = user.getData().getPowertool(itemStack.getType());
if (command != null && !command.isEmpty())
{
if (command.equalsIgnoreCase("l:"))
{
if (powertools == null || powertools.isEmpty())
{
throw new Exception(_("powerToolListEmpty", itemName));
}
else
{
user.sendMessage(_("powerToolList", Util.joinList(powertools), itemName));
}
return;
}
if (command.startsWith("r:"))
{
try
{
command = command.substring(2);
if (!powertools.contains(command))
{
throw new Exception(_("powerToolNoSuchCommandAssigned", command, itemName));
}
powertools.remove(command);
user.sendMessage(_("powerToolRemove", command, itemName));
}
catch (Exception e)
{
user.sendMessage(e.getMessage());
return;
}
}
else
{
if (command.startsWith("a:"))
{
if (!user.isAuthorized("essentials.powertool.append"))
{
throw new Exception(_("noPerm", "essentials.powertool.append"));
}
command = command.substring(2);
if (powertools.contains(command))
{
throw new Exception(_("powerToolAlreadySet", command, itemName));
}
}
else if (powertools != null && !powertools.isEmpty())
{
// Replace all commands with this one
powertools.clear();
}
else
{
powertools = new ArrayList<String>();
}
powertools.add(command);
user.sendMessage(_("powerToolAttach", Util.joinList(powertools), itemName));
}
}
else
{
if (powertools != null)
{
powertools.clear();
}
user.sendMessage(_("powerToolRemoveAll", itemName));
}
user.acquireWriteLock();
user.getData().setPowertool(itemStack.getType(), powertools);
}
}
|