mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
EntityDamageEvent and children now only fire if the attack is possible, moved event trigger to Entity->attack()
This commit is contained in:
@ -1901,7 +1901,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
if($cancelled){
|
||||
$ev->setCancelled();
|
||||
}
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
|
||||
$target->attack($ev->getFinalDamage(), $ev);
|
||||
|
||||
if($ev->isCancelled()){
|
||||
if($item->isTool() and $this->isSurvival()){
|
||||
$this->inventory->sendContents($this);
|
||||
@ -1909,8 +1911,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
break;
|
||||
}
|
||||
|
||||
$target->attack($ev->getFinalDamage(), $ev);
|
||||
|
||||
if($item->isTool() and $this->isSurvival()){
|
||||
if($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()){
|
||||
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1), $this);
|
||||
@ -2517,7 +2517,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
if($this->dead === true){
|
||||
return;
|
||||
}
|
||||
if(($this->getGamemode() & 0x01) === 1){
|
||||
if($this->isCreative() === 1){
|
||||
if($source instanceof EntityDamageEvent){
|
||||
$cause = $source->getCause();
|
||||
}else{
|
||||
@ -2529,6 +2529,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
and $cause !== EntityDamageEvent::CAUSE_SUICIDE
|
||||
and $cause !== EntityDamageEvent::CAUSE_VOID
|
||||
){
|
||||
if($source instanceof EntityDamageEvent){
|
||||
$source->setCancelled();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -2536,6 +2539,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
parent::attack($damage, $source);
|
||||
|
||||
if($source instanceof EntityDamageEvent and $source->isCancelled()){
|
||||
return;
|
||||
}
|
||||
|
||||
if($this->getLastDamageCause() === $source){
|
||||
$pk = EntityEventPacket::getFromPool();
|
||||
$pk->eid = 0;
|
||||
|
Reference in New Issue
Block a user