2011-05-29 13:25:25 +02:00
|
|
|
package com.Acrobot.ChestShop.Commands;
|
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
|
|
|
import com.Acrobot.Breeze.Utils.StringUtil;
|
|
|
|
import com.Acrobot.ChestShop.ChestShop;
|
2012-11-23 21:04:13 +01:00
|
|
|
import com.Acrobot.ChestShop.Configuration.Messages;
|
2012-06-08 15:28:36 +02:00
|
|
|
import com.Acrobot.ChestShop.Events.ItemInfoEvent;
|
2011-08-13 12:08:34 +02:00
|
|
|
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;
|
2012-06-08 15:28:36 +02:00
|
|
|
import org.bukkit.entity.HumanEntity;
|
2011-05-29 13:25:25 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
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) {
|
2011-08-13 12:08:34 +02:00
|
|
|
ItemStack item;
|
2012-06-08 15:28:36 +02:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
if (args.length == 0) {
|
2012-06-08 15:28:36 +02:00
|
|
|
if (!(sender instanceof HumanEntity)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
item = ((HumanEntity) sender).getItemInHand();
|
2011-05-29 13:25:25 +02:00
|
|
|
} else {
|
2012-06-08 15:28:36 +02:00
|
|
|
item = MaterialUtil.getItem(StringUtil.joinArray(args));
|
2011-08-13 12:08:34 +02:00
|
|
|
}
|
2011-05-29 13:25:25 +02:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
if (MaterialUtil.isEmpty(item)) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-03-17 15:00:25 +01:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
String durability = getDurability(item);
|
|
|
|
String enchantment = getEnchantment(item);
|
2011-05-29 13:25:25 +02:00
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
sender.sendMessage(Messages.prefix(iteminfo));
|
2012-06-08 15:28:36 +02:00
|
|
|
sender.sendMessage(getNameAndID(item) + durability + enchantment + ChatColor.WHITE);
|
2011-12-16 17:20:09 +01:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
ItemInfoEvent event = new ItemInfoEvent(sender, item);
|
|
|
|
ChestShop.callEvent(event);
|
2011-12-16 17:20:09 +01:00
|
|
|
|
2011-08-13 12:08:34 +02:00
|
|
|
return true;
|
2012-06-08 15:28:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static String getNameAndID(ItemStack item) {
|
|
|
|
String itemName = MaterialUtil.getName(item);
|
2011-05-29 13:25:25 +02:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
return ChatColor.GRAY + itemName + ChatColor.WHITE + " " + item.getTypeId();
|
2011-05-29 13:25:25 +02:00
|
|
|
}
|
2012-03-17 15:00:25 +01:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
private static String getDurability(ItemStack item) {
|
|
|
|
if (item.getDurability() != 0) {
|
|
|
|
return ChatColor.DARK_GREEN + ":" + Integer.toString(item.getDurability());
|
|
|
|
} else {
|
|
|
|
return "";
|
2012-05-10 16:32:25 +02:00
|
|
|
}
|
2011-12-16 17:20:09 +01:00
|
|
|
}
|
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
private static String getEnchantment(ItemStack item) {
|
|
|
|
String encodedEnchantments = MaterialUtil.Enchantment.encodeEnchantment(item);
|
2012-03-17 15:00:25 +01:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
if (encodedEnchantments != null) {
|
|
|
|
return ChatColor.DARK_AQUA + "-" + encodedEnchantments;
|
|
|
|
} else {
|
|
|
|
return "";
|
2012-05-10 16:32:25 +02:00
|
|
|
}
|
2011-12-16 17:20:09 +01:00
|
|
|
}
|
2011-05-29 13:25:25 +02:00
|
|
|
}
|