TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/Commanditemdb.java

52 lines
1.2 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
2011-12-06 21:58:44 +00:00
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
2011-12-06 21:58:44 +00:00
public class Commanditemdb extends EssentialsCommand
{
2011-12-06 21:58:44 +00:00
public Commanditemdb()
{
super("itemdb");
}
@Override
protected void run(Server server, CommandSender sender, String commandLabel, String[] args) throws Exception
{
2011-12-06 21:58:44 +00:00
ItemStack itemStack = null;
boolean itemHeld = false;
if (args.length < 1)
{
2011-12-06 21:58:44 +00:00
if (sender instanceof Player)
{
itemHeld = true;
2011-12-06 21:58:44 +00:00
itemStack = ((Player)sender).getItemInHand();
}
if (itemStack == null)
{
throw new NotEnoughArgumentsException();
}
}
else
{
itemStack = ess.getItemDb().get(args[0]);
}
2012-08-03 08:02:47 +00:00
sender.sendMessage(itemStack.getType().toString() + "- " + itemStack.getTypeId() + ":" + Integer.toString(itemStack.getDurability()));
2012-06-10 17:33:07 +00:00
if (itemHeld && itemStack.getType() != Material.AIR)
{
2012-06-10 17:33:07 +00:00
int maxuses = itemStack.getType().getMaxDurability();
int durability = ((maxuses + 1) - itemStack.getDurability());
if (maxuses != 0)
{
sender.sendMessage(_("durability", Integer.toString(durability)));
}
}
}
}