ChestShop-3/com/Acrobot/ChestShop/Commands/ItemInfo.java

72 lines
2.1 KiB
Java
Raw Normal View History

2011-05-29 13:25:25 +02:00
package com.Acrobot.ChestShop.Commands;
import com.Acrobot.Breeze.Utils.MaterialUtil;
import com.Acrobot.Breeze.Utils.StringUtil;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Events.ItemInfoEvent;
import org.bukkit.ChatColor;
2011-05-29 13:25:25 +02:00
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.HumanEntity;
2011-05-29 13:25:25 +02:00
import org.bukkit.inventory.ItemStack;
import static com.Acrobot.ChestShop.Configuration.Messages.iteminfo;
2011-05-29 13:25:25 +02:00
/**
* @author Acrobot
*/
public class ItemInfo implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
ItemStack item;
2011-05-29 13:25:25 +02:00
if (args.length == 0) {
if (!(sender instanceof HumanEntity)) {
return false;
}
item = ((HumanEntity) sender).getItemInHand();
2011-05-29 13:25:25 +02:00
} else {
item = MaterialUtil.getItem(StringUtil.joinArray(args));
}
2011-05-29 13:25:25 +02:00
if (MaterialUtil.isEmpty(item)) {
return false;
}
String durability = getDurability(item);
2013-01-24 22:35:28 +01:00
String metadata = getMetadata(item);
2011-05-29 13:25:25 +02:00
sender.sendMessage(Messages.prefix(iteminfo));
2013-01-24 22:35:28 +01:00
sender.sendMessage(getNameAndID(item) + durability + metadata + ChatColor.WHITE);
ItemInfoEvent event = new ItemInfoEvent(sender, item);
ChestShop.callEvent(event);
return true;
}
private static String getNameAndID(ItemStack item) {
String itemName = MaterialUtil.getName(item);
2011-05-29 13:25:25 +02:00
return ChatColor.GRAY + itemName + ChatColor.WHITE + " " + item.getTypeId();
2011-05-29 13:25:25 +02:00
}
private static String getDurability(ItemStack item) {
if (item.getDurability() != 0) {
return ChatColor.DARK_GREEN + ":" + Integer.toString(item.getDurability());
} else {
return "";
}
}
2013-01-24 22:35:28 +01:00
private static String getMetadata(ItemStack item) {
if (!item.hasItemMeta()) {
return "";
}
2013-01-24 22:35:28 +01:00
return ChatColor.GOLD + "#" + MaterialUtil.Metadata.getItemCode(item);
}
2011-05-29 13:25:25 +02:00
}