mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2025-02-16 02:11:18 +01:00
Fix custom item code getting generated for items with damage (Fixes #598)
This commit is contained in:
parent
ec8032a688
commit
6a2a3a4b36
@ -268,7 +268,7 @@ public class MaterialUtil {
|
||||
}
|
||||
|
||||
String metaData = "";
|
||||
if (itemStack.hasItemMeta()) {
|
||||
if (hasCustomData(itemStack)) {
|
||||
metaData = "#" + Metadata.getItemCode(itemStack);
|
||||
}
|
||||
|
||||
@ -284,6 +284,29 @@ public class MaterialUtil {
|
||||
return code + durability + metaData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the provided ItemStack has custom data (in the past called "ItemMeta"). This will ignore
|
||||
* the durability of an item.
|
||||
*
|
||||
* @param itemStack The ItemStack to check
|
||||
* @return Whether the item has custom data
|
||||
*/
|
||||
private static boolean hasCustomData(ItemStack itemStack) {
|
||||
if (!itemStack.hasItemMeta()) {
|
||||
return false;
|
||||
}
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (itemMeta instanceof Damageable) {
|
||||
if (!((Damageable) itemMeta).hasDamage()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Map<String, Object> data = itemMeta.serialize();
|
||||
// if the data map contains more than the metadata type and the damage
|
||||
// then the item does indeed have custom data set
|
||||
return data.size() > 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item name shortened to a max length that is still reversable by {@link #getMaterial(String)}
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user