mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-25 11:35:28 +01:00
Fix issue with durability not being set (Fixes #597)
Previously there was no difference between 0 and "not set" but since 1.20.6 it's necessary to differentiate between them. This adjusts it so that the damage is no longer set to 0 if no value was in the item name string.
This commit is contained in:
parent
07dd3c7a70
commit
32aa1403c9
@ -390,8 +390,8 @@ public class MaterialUtil {
|
||||
split[i] = split[i].trim();
|
||||
}
|
||||
|
||||
int durability = getDurability(itemName);
|
||||
MaterialParseEvent parseEvent = new MaterialParseEvent(split[0], (short) durability);
|
||||
Integer durability = getDurability(itemName);
|
||||
MaterialParseEvent parseEvent = new MaterialParseEvent(split[0], durability != null ? durability.shortValue() : 0);
|
||||
Bukkit.getPluginManager().callEvent(parseEvent);
|
||||
Material material = parseEvent.getMaterial();
|
||||
if (material == null) {
|
||||
@ -402,10 +402,16 @@ public class MaterialUtil {
|
||||
|
||||
ItemMeta meta = getMetadata(itemName);
|
||||
|
||||
if (meta != null) {
|
||||
if (durability != null) {
|
||||
if (meta == null) {
|
||||
meta = itemStack.getItemMeta();
|
||||
}
|
||||
if (meta instanceof Damageable) {
|
||||
((Damageable) meta).setDamage(durability);
|
||||
}
|
||||
}
|
||||
|
||||
if (meta != null) {
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
@ -418,17 +424,17 @@ public class MaterialUtil {
|
||||
* @param itemName Item name
|
||||
* @return Durability found
|
||||
*/
|
||||
public static int getDurability(String itemName) {
|
||||
public static Integer getDurability(String itemName) {
|
||||
Matcher m = DURABILITY.matcher(itemName);
|
||||
|
||||
if (!m.find()) {
|
||||
return 0;
|
||||
return null;
|
||||
}
|
||||
|
||||
String data = m.group();
|
||||
|
||||
if (data == null || data.isEmpty()) {
|
||||
return 0;
|
||||
return null;
|
||||
}
|
||||
|
||||
data = data.substring(1);
|
||||
|
Loading…
Reference in New Issue
Block a user