I am creating a plugin where it needs to detect if a player is hit by a special snowball. (which is done with namedtag stuff) How would I define the snowball that was thrown to the player? PHP: public function onDamage(EntityDamageEvent $event){ $player = $event->getEntity(); $snowball = // ??? if($event->getCause() === EntityDamageEvent::CAUSE_PROJECTILE && /* What would go in here too?*/){ $event->setDamage(10); $player->sendMessage("You have been hit by a bullet from other player."); } }
$snowball = $event->getDamager() * && $snowball instanceof Snowball !! Just an idea, haven't checked it yet.
Use if($event instanceof EntityDamageByEntityEvent), then if $event->getDamager() instanceof Snowball
Ty! I will try that out soon! So the projectile I was hit by can be defined with getDamager! I thought this meant something like getEntity... XD
Yup, I re-read the docs. I meant that I misunderstood that it will return the attacker, not the projectile entity.
PHP: if($cause == EntityDamageEvent::CAUSE_PROJECTILE){ if($event instanceof EntityDamageByChildEntityEvent){ $killer = $event->getDamager();$snowball = $event->getChild(); if($snowball instanceof Snowball){//your stuff } } Thanks to @PEMapModder to remind me about getChild()