diff --git a/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java b/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java index be0d9de..777a616 100644 --- a/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java +++ b/src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java @@ -206,17 +206,19 @@ public class MaterialUtil { metaData = "#" + Metadata.getItemCode(itemStack); } - String code = data + itemName + durability + metaData; - if (maxLength > 0 && code.length() > maxLength) { - int exceeding = code.length() - maxLength; - code = data + getShortenedName(itemName, itemName.length() - exceeding) + durability + metaData; + int codeLength = (data + itemName + durability + metaData).length(); + String code = data + itemName; + if (maxLength > 0 && codeLength > maxLength) { + int exceeding = codeLength - maxLength; + code = getShortenedName(code, code.length() - exceeding); } - - code = StringUtil.capitalizeFirstLetter(code, '_'); - + + code = StringUtil.capitalizeFirstLetter(code, '_') + durability + metaData; + ItemStack codeItem = getItem(code); if (!equals(itemStack, codeItem)) { - throw new IllegalArgumentException("Cannot generate code for item " + itemStack + " with maximum length of " + maxLength + "(tried code " + code); + throw new IllegalArgumentException("Cannot generate code for item " + itemStack + " with maximum length of " + maxLength + + " (code " + code + " results in item " + codeItem + ")"); } return code; diff --git a/src/main/java/com/Acrobot/ChestShop/Commands/ItemInfo.java b/src/main/java/com/Acrobot/ChestShop/Commands/ItemInfo.java index b21a1eb..59b2f69 100644 --- a/src/main/java/com/Acrobot/ChestShop/Commands/ItemInfo.java +++ b/src/main/java/com/Acrobot/ChestShop/Commands/ItemInfo.java @@ -36,8 +36,17 @@ public class ItemInfo implements CommandExecutor { } sender.sendMessage(Messages.prefix(iteminfo)); - sender.sendMessage(ChatColor.WHITE + "Full Name: " + ChatColor.GRAY + MaterialUtil.getName(item)); - sender.sendMessage(ChatColor.WHITE + "Shop Sign: " + ChatColor.GRAY + MaterialUtil.getSignName(item)); + try { + sender.sendMessage(ChatColor.WHITE + "Full Name: " + ChatColor.GRAY + MaterialUtil.getName(item)); + } catch (IllegalArgumentException e) { + sender.sendMessage(ChatColor.RED + "Full Name Error: " + e.getMessage()); + } + + try { + sender.sendMessage(ChatColor.WHITE + "Shop Sign: " + ChatColor.GRAY + MaterialUtil.getSignName(item)); + } catch (IllegalArgumentException e) { + sender.sendMessage(ChatColor.RED + "Shop Sign Error: " + e.getMessage()); + } ItemInfoEvent event = new ItemInfoEvent(sender, item); ChestShop.callEvent(event);