blob: 108644649c42f6ac3c29e046f13ceb0468f4a5f0 (
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.MetaItemStack;
import com.earth2me.essentials.Potions;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.StringUtil;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public class Commandpotion extends EssentialsCommand
{
public Commandpotion()
{
super("potion");
}
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
final ItemStack stack = user.getBase().getItemInHand();
if (args.length == 0)
{
final Set<String> potionslist = new TreeSet<String>();
for (Map.Entry<String, PotionEffectType> entry : Potions.entrySet())
{
final String potionName = entry.getValue().getName().toLowerCase(Locale.ENGLISH);
if (potionslist.contains(potionName) || (user.isAuthorized("essentials.potion." + potionName)))
{
potionslist.add(entry.getKey());
}
}
throw new NotEnoughArgumentsException(tl("potions", StringUtil.joinList(potionslist.toArray())));
}
if (stack.getType() == Material.POTION)
{
PotionMeta pmeta = (PotionMeta)stack.getItemMeta();
if (args.length > 0)
{
if (args[0].equalsIgnoreCase("clear"))
{
pmeta.clearCustomEffects();
stack.setItemMeta(pmeta);
}
else if (args[0].equalsIgnoreCase("apply") && user.isAuthorized("essentials.potion.apply"))
{
for (PotionEffect effect : pmeta.getCustomEffects())
{
effect.apply(user.getBase());
}
}
else if (args.length < 3)
{
throw new NotEnoughArgumentsException();
}
else
{
final MetaItemStack mStack = new MetaItemStack(stack);
for (String arg : args)
{
mStack.addPotionMeta(user.getSource(), true, arg, ess);
}
if (mStack.completePotion())
{
pmeta = (PotionMeta)mStack.getItemStack().getItemMeta();
stack.setItemMeta(pmeta);
}
else
{
user.sendMessage(tl("invalidPotion"));
throw new NotEnoughArgumentsException();
}
}
}
}
else
{
throw new Exception(tl("holdPotion"));
}
}
}
|