EntityDamageEvent and children now only fire if the attack is possible, moved event trigger to Entity->attack()

This commit is contained in:
Shoghi Cervantes
2014-10-29 16:02:40 +01:00
parent 289bc56b4b
commit 8a768cea33
10 changed files with 33 additions and 66 deletions

View File

@ -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;