Prevent internal NPE on ItemStack#damage (#10836)
ItemStack#damage internally uses ItemStack#hurtAndBreak, which previously would call a Consumer in case the item broke. Since 1.20.5 the break game event logic however resides in said method and was using the equipment slot passed, which is null in the case of the API ItemStack#damage method. This commit prevents the NPE by first null checking the slot. Addittionally, hurtAndBreak also now checks if the player has infinite materials, e.g. is in creative mode, to prevent damaging the item. As such as filter is undesirable for API calls, this commit also skips this logic in case of an API invocation.
This commit is contained in:
parent
bd9e2e7fe8
commit
5df0660d63
2 changed files with 30 additions and 2 deletions
|
@ -137,7 +137,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
||||
@@ -0,0 +0,0 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
nmsStack.hurtAndBreak(amount, this.getHandle(), slot);
|
||||
nmsStack.hurtAndBreakWithoutChecks(amount, this.getHandle(), slot);
|
||||
}
|
||||
// Paper end - ItemStack damage API
|
||||
+
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue