Skip to content

Commit

Permalink
ItemUtils - fix error when setting damage lower than 0 (SkriptLang#6870)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneBeee authored Jul 10, 2024
1 parent 8a5ceae commit c782652
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/bukkitutil/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static void setMaxDamage(ItemStack itemStack, int maxDamage) {
public static void setDamage(ItemStack itemStack, int damage) {
ItemMeta meta = itemStack.getItemMeta();
if (meta instanceof Damageable) {
((Damageable) meta).setDamage(damage);
((Damageable) meta).setDamage(Math.max(0, damage));
itemStack.setItemMeta(meta);
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/skript/tests/syntaxes/expressions/ExprDurability.sk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ test "durability":
assert damage of {_i} is {_max} with "max item damage failed"
assert durability of {_i} is 0 with "zero item durability failed"

# Test out of bound values
set durability of {_i} to 500
assert damage of {_i} is 0 with "damage of item should be 0 when setting durability higher than max"
assert durability of {_i} is {_max} with "durability of item should be max when setting higher than max"

set damage of {_i} to -1
assert damage of {_i} is 0 with "damage of item should be 0 when setting damage less than 0"
assert durability of {_i} is {_max} with "durability of item should be max when setting damage below 0"

test "durability - custom" when running minecraft "1.20.5":
set {_i} to 1 of iron sword
set max durability of {_i} to 1000
Expand Down

0 comments on commit c782652

Please sign in to comment.