blob: d4534f55a3ca4308560d0cab695a5a423f0d1ca6 (
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
|
package net.ess3.commands;
import static net.ess3.I18n._;
import net.ess3.api.IUser;
import net.ess3.craftbukkit.InventoryWorkaround;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
public class Commandhat extends EssentialsCommand
{
@Override
protected void run(IUser user, String commandLabel, String[] args) throws Exception
{
if (args.length > 0 && (args[0].contains("rem") || args[0].contains("off") || args[0].equalsIgnoreCase("0")))
{
final PlayerInventory inv = user.getPlayer().getInventory();
final ItemStack head = inv.getHelmet();
if (head == null || head.getType() == Material.AIR)
{
user.sendMessage(_("hatEmpty"));
}
else
{
final ItemStack air = new ItemStack(Material.AIR);
inv.setHelmet(air);
InventoryWorkaround.addItem(user.getPlayer().getInventory(), true, head);
user.sendMessage(_("hatRemoved"));
}
}
else
{
if (user.getPlayer().getItemInHand().getType() != Material.AIR)
{
final ItemStack hand = user.getPlayer().getItemInHand();
if (hand.getType().getMaxDurability() == 0)
{
final PlayerInventory inv = user.getPlayer().getInventory();
final ItemStack head = inv.getHelmet();
inv.removeItem(hand);
inv.setHelmet(hand);
inv.setItemInHand(head);
user.sendMessage(_("hatPlaced"));
}
else
{
user.sendMessage(_("hatArmor"));
}
}
else
{
user.sendMessage(_("hatFail"));
}
}
}
}
|