Fix issues with metadata IDs

Also log more info when the code couldn't be generated and send it to the sender when the iteminfo command is used
This commit is contained in:
Phoenix616 2018-03-16 18:24:52 +01:00
parent 51495cdefb
commit dd44217132
2 changed files with 21 additions and 10 deletions

View File

@ -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;

View File

@ -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);