Skip to content

Commit

Permalink
Fix issue with durability not being set (Fixes #597)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Phoenix616 committed Jun 19, 2024
1 parent 07dd3c7 commit 32aa140
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/main/java/com/Acrobot/Breeze/Utils/MaterialUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ public static ItemStack getItem(String itemName) {
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) {
Expand All @@ -402,10 +402,16 @@ public static ItemStack getItem(String itemName) {

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

Expand All @@ -418,17 +424,17 @@ public static ItemStack getItem(String itemName) {
* @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);
Expand Down

0 comments on commit 32aa140

Please sign in to comment.