Player: avoid doing some post-melee attack actions if attacking killed the attacker

This can happen when an attacker attacks a victim wearing thorns armour while having low health, which prior to this commit would cause the tool to be duplicated.
This commit is contained in:
Dylan K. Taylor 2018-06-22 17:17:40 +01:00
parent a5a236084f
commit 6c6630d845

View File

@ -2529,11 +2529,15 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}
}
if($heldItem->onAttackEntity($target) and $this->isSurvival()){ //always fire the hook, even if we are survival
$this->inventory->setItemInHand($heldItem);
}
if($this->isAlive()){
//reactive damage like thorns might cause us to be killed by attacking another mob, which
//would mean we'd already have dropped the inventory by the time we reached here
if($heldItem->onAttackEntity($target) and $this->isSurvival()){ //always fire the hook, even if we are survival
$this->inventory->setItemInHand($heldItem);
}
$this->exhaust(0.3, PlayerExhaustEvent::CAUSE_ATTACK);
$this->exhaust(0.3, PlayerExhaustEvent::CAUSE_ATTACK);
}
return true;
default: