mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-12-20 07:17:34 +01:00
5908eb67fa
- Copied utilities from ChestShop-4 - Made code really, really nicer to read - Made every external plugin's wrapper a listener, so it listens to events instead of being hard-coded.
73 lines
2.2 KiB
Java
73 lines
2.2 KiB
Java
package com.Acrobot.ChestShop.Commands;
|
|
|
|
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
|
import com.Acrobot.Breeze.Utils.MessageUtil;
|
|
import com.Acrobot.Breeze.Utils.StringUtil;
|
|
import com.Acrobot.ChestShop.ChestShop;
|
|
import com.Acrobot.ChestShop.Config.Language;
|
|
import com.Acrobot.ChestShop.Events.ItemInfoEvent;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.HumanEntity;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
/**
|
|
* @author Acrobot
|
|
*/
|
|
public class ItemInfo implements CommandExecutor {
|
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
ItemStack item;
|
|
|
|
if (args.length == 0) {
|
|
if (!(sender instanceof HumanEntity)) {
|
|
return false;
|
|
}
|
|
|
|
item = ((HumanEntity) sender).getItemInHand();
|
|
} else {
|
|
item = MaterialUtil.getItem(StringUtil.joinArray(args));
|
|
}
|
|
|
|
if (MaterialUtil.isEmpty(item)) {
|
|
return false;
|
|
}
|
|
|
|
String durability = getDurability(item);
|
|
String enchantment = getEnchantment(item);
|
|
|
|
MessageUtil.sendMessage(sender, Language.iteminfo);
|
|
sender.sendMessage(getNameAndID(item) + durability + enchantment + ChatColor.WHITE);
|
|
|
|
ItemInfoEvent event = new ItemInfoEvent(sender, item);
|
|
ChestShop.callEvent(event);
|
|
|
|
return true;
|
|
}
|
|
|
|
private static String getNameAndID(ItemStack item) {
|
|
String itemName = MaterialUtil.getName(item);
|
|
|
|
return ChatColor.GRAY + itemName + ChatColor.WHITE + " " + item.getTypeId();
|
|
}
|
|
|
|
private static String getDurability(ItemStack item) {
|
|
if (item.getDurability() != 0) {
|
|
return ChatColor.DARK_GREEN + ":" + Integer.toString(item.getDurability());
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
private static String getEnchantment(ItemStack item) {
|
|
String encodedEnchantments = MaterialUtil.Enchantment.encodeEnchantment(item);
|
|
|
|
if (encodedEnchantments != null) {
|
|
return ChatColor.DARK_AQUA + "-" + encodedEnchantments;
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|
|
}
|