PHP: foreach($pos->getLevel()->getNearbyEntities(new AxisAlignedBB($pos->getFloorX() - ($radius = 5), $pos->getFloorY() - $radius, $pos->getFloorZ() - $radius, $pos->getFloorX() + $radius, $pos->getFloorY() + $radius, $pos->getFloorZ() + $radius), $pos) as $e){ $e->attack(0, new EntityDamageEvent($pos, EntityDamageEvent::CAUSE_MAGIC, $damage)); } How do i make this to like only damage the Entity if the EntityDamageEvent isn't cancelled?
PHP: foreach($pos->getLevel()->getNearbyEntities(new AxisAlignedBB($pos->getFloorX() - ($radius = 5), $pos->getFloorY() - $radius, $pos->getFloorZ() - $radius, $pos->getFloorX() + $radius, $pos->getFloorY() + $radius, $pos->getFloorZ() + $radius), $pos) as $e){ if(!$event->isCancelled()){ $e->attack(0, new EntityDamageEvent($pos, EntityDamageEvent::CAUSE_MAGIC, $damage)); } }
PHP: public function strikeLightning(Position $pos, int $damage = 0){ $pk = $this->lightning($pos); foreach($pos->getLevel()->getPlayers() as $p){ $p->dataPacket($pk); } if(!$pos instanceof Entity and !($pos = $this->createTNT($pos, null, false))){ return; } foreach($pos->getLevel()->getNearbyEntities(new AxisAlignedBB($pos->getFloorX() - ($radius = 5), $pos->getFloorY() - $radius, $pos->getFloorZ() - $radius, $pos->getFloorX() + $radius, $pos->getFloorY() + $radius, $pos->getFloorZ() + $radius), $pos) as $e){ $e->attack(0, new EntityDamageEvent($pos, EntityDamageEvent::CAUSE_MAGIC, $damage)); } } $event isn't declared.
I don't think you can change that like that. You might have to add some code in a listener to mimic what you want. For example: on entity damage event cancel it if its cause is CAUSE_MAGIC in specified worlds / locations.
There does not exist a method EventObject->isCancelled(). There only exists the method Event->isCancelled().