2012-05-27 07:24:49 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2014-03-20 15:54:07 +00:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
2012-05-27 07:24:49 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2012-06-15 20:36:26 +00:00
|
|
|
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
|
2012-05-27 07:24:49 +00:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
|
|
|
|
|
|
|
|
|
|
public class Commandhat extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commandhat()
|
|
|
|
{
|
|
|
|
super("hat");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-06-16 13:02:13 +00:00
|
|
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
2012-05-27 07:24:49 +00:00
|
|
|
{
|
2012-06-16 13:02:13 +00:00
|
|
|
if (args.length > 0 && (args[0].contains("rem") || args[0].contains("off") || args[0].equalsIgnoreCase("0")))
|
|
|
|
{
|
2014-04-13 00:01:49 +00:00
|
|
|
final PlayerInventory inv = user.getBase().getInventory();
|
2012-06-16 13:02:13 +00:00
|
|
|
final ItemStack head = inv.getHelmet();
|
|
|
|
if (head == null || head.getType() == Material.AIR)
|
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
user.sendMessage(tl("hatEmpty"));
|
2012-06-16 13:02:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
final ItemStack air = new ItemStack(Material.AIR);
|
|
|
|
inv.setHelmet(air);
|
2014-04-13 00:01:49 +00:00
|
|
|
InventoryWorkaround.addItems(user.getBase().getInventory(), head);
|
2014-03-20 15:54:07 +00:00
|
|
|
user.sendMessage(tl("hatRemoved"));
|
2012-06-16 13:02:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2012-05-27 07:24:49 +00:00
|
|
|
{
|
2014-04-13 00:01:49 +00:00
|
|
|
if (user.getBase().getItemInHand().getType() != Material.AIR)
|
2012-05-27 07:36:04 +00:00
|
|
|
{
|
2014-04-13 00:01:49 +00:00
|
|
|
final ItemStack hand = user.getBase().getItemInHand();
|
2012-06-15 20:36:26 +00:00
|
|
|
if (hand.getType().getMaxDurability() == 0)
|
|
|
|
{
|
2014-04-13 00:01:49 +00:00
|
|
|
final PlayerInventory inv = user.getBase().getInventory();
|
2012-06-15 20:36:26 +00:00
|
|
|
final ItemStack head = inv.getHelmet();
|
|
|
|
inv.setHelmet(hand);
|
|
|
|
inv.setItemInHand(head);
|
2014-03-20 15:54:07 +00:00
|
|
|
user.sendMessage(tl("hatPlaced"));
|
2012-06-16 13:02:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
user.sendMessage(tl("hatArmor"));
|
2012-06-15 20:36:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
user.sendMessage(tl("hatFail"));
|
2012-05-27 07:36:04 +00:00
|
|
|
}
|
2012-05-27 07:24:49 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-15 20:36:26 +00:00
|
|
|
}
|