ChestShop-3/com/Acrobot/ChestShop/Commands/ItemInfo.java
Acrobot a49d51ce97 - Changed to the new, more robust event system
- Added partial transactions (You have 5 items, shop wants 10 - you can sell your items for half the price)
- Added a warning to the HTML generator
- Fixed Towny integration
- Fixed occasional ArrayOutOfBoundsExceptions
- Fixed an error when a shop couldn't be created because a sign (not shop sign) was on other side of the block
- Added SCL (SimpleChestLock) protection plugin to supported plugins
- Updated Metrics (and added a new asynch thread for startup)
- Removed Bukkit-1.0 workaround
- Fixed plugin.yml formatting
2012-02-16 19:09:37 +01:00

68 lines
2.4 KiB
Java

package com.Acrobot.ChestShop.Commands;
import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Language;
import com.Acrobot.ChestShop.Items.Items;
import com.Acrobot.ChestShop.Utils.uEnchantment;
import com.Acrobot.ChestShop.Utils.uSign;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Map;
/**
* @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 Player)) return false;
item = ((Player) sender).getItemInHand();
} else {
item = Items.getItemStack(joinArray(args));
}
if (item == null || item.getType() == Material.AIR) return false;
String durability = (item.getDurability() != 0 ? ChatColor.DARK_GREEN + ":" + item.getDurability() : "");
String ench = uEnchantment.getEnchantment(item);
String enchantment = (ench != null ? ChatColor.DARK_AQUA + "-" + ench : "");
sender.sendMessage(Config.getLocal(Language.iteminfo));
String itemname = Items.getName(item);
sender.sendMessage(ChatColor.GRAY + itemname + ChatColor.WHITE + " "
+ item.getTypeId() + durability + enchantment + ChatColor.WHITE);
Map<Enchantment, Integer> map = item.getEnchantments();
for (Map.Entry<Enchantment, Integer> e : map.entrySet())
sender.sendMessage(ChatColor.DARK_GRAY + uSign.capitalizeFirst(e.getKey().getName()) + ' ' + intToRoman(e.getValue()));
return true;
}
private static String intToRoman(int integer){
if (integer == 1) return "I";
if (integer == 2) return "II";
if (integer == 3) return "III";
if (integer == 4) return "IV";
if (integer == 5) return "V";
return Integer.toString(integer);
}
private static String joinArray(String[] array){
StringBuilder b = new StringBuilder(array.length);
for (String s : array) b.append(s).append(' ');
return b.toString();
}
}