コード例 #1
0
ファイル: ItemInfo.java プロジェクト: Acrobot/ChestShop4
 private static void sendEnchantments(
     Map<Enchantment, Integer> enchantments, CommandSender sender) {
   for (Map.Entry<Enchantment, Integer> enchantment : enchantments.entrySet()) {
     sender.sendMessage(
         ChatColor.DARK_GRAY
             + StringUtil.capitalizeFirstLetter(enchantment.getKey().getName())
             + ' '
             + NumberUtil.numberToRoman(enchantment.getValue()));
   }
 }
コード例 #2
0
ファイル: ItemInfo.java プロジェクト: Acrobot/ChestShop4
  @Command(
      command = "iteminfo",
      aliases = {"iinfo"},
      description = "Shows information about items",
      syntax =
          "/iteminfo §2(what's the item in hand?) \n"
              + "/iteminfo §712§f §2(what's the item with ID §712§2?) \n"
              + "/iteminfo §7log§f §2(what's the item ID of §7LOG§2?)")
  public static boolean itemInfo(CommandSender sender, String currentAlias, String[] args) {
    ItemStack item;

    if (args.length == 0) {
      if (!(sender instanceof Player)) {
        return false;
      }

      item = ((Player) sender).getItemInHand();
    } else {
      item = MaterialUtil.getItem(StringUtil.joinArray(args));
    }

    if (item == null || item.getType() == Material.AIR) {
      return false;
    }

    String durability =
        (item.getDurability() != 0 ? ChatColor.DARK_GREEN + ":" + item.getDurability() : "");

    String enchantmentString = MaterialUtil.Enchantments.encodeEnchantment(item.getEnchantments());
    String enchantment =
        (enchantmentString != null ? ChatColor.DARK_AQUA + "-" + enchantmentString : "");

    String itemName = MaterialUtil.getName(item);

    EventUtils.sendMessage(new MessageEvent("iteminfo"), sender);

    sender.sendMessage(
        ChatColor.GRAY
            + itemName
            + ChatColor.WHITE
            + "     "
            + item.getTypeId()
            + durability
            + enchantment);

    sendEnchantments(item.getEnchantments(), sender);

    return true;
  }