Player: fixed crash on action item return

this can happen if the old item had a lower max damage than the new one, and the new
one has a damage higher than the old one's max damage.

it can also happen if the damage was overridden to some illegal value by a custom item
as seen in https://crash.pmmp.io/view/12754811
This commit is contained in:
Dylan K. Taylor 2025-05-28 21:32:48 +01:00
parent a554d2acf5
commit b40b99fe72
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -1641,7 +1641,10 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$newReplica = clone $oldHeldItem;
$newReplica->setCount($newHeldItem->getCount());
if($newReplica instanceof Durable && $newHeldItem instanceof Durable){
$newReplica->setDamage($newHeldItem->getDamage());
$newDamage = $newHeldItem->getDamage();
if($newDamage >= 0 && $newDamage <= $newReplica->getMaxDurability()){
$newReplica->setDamage($newDamage);
}
}
$damagedOrDeducted = $newReplica->equalsExact($newHeldItem);