Getting the arrow and the arrow shooter do I already know, but how can I get the Player (yes, player), who got hit by the arrow?
For Example PHP: public function onDamage(EntityDamageEvent $event){if($event instanceof \pocketmine\event\entity\EntityDamageByEntityEvent){$damager = $event->getDamager();if($event instanceof \pocketmine\event\entity\EntityDamageByChildEntityEvent){if($damager instanceof \pocketmine\Player){$player = $event->getEntity();}}}}
Try this. PHP: public function onDamage(EntityDamageEvent $e){$p = $e->getEntity();$arrow = $p->getLastDamageCause();if(($arrow instanceof Projectile) and ($arrow instanceof \pocketmine\entity\Arrow)){//do something}}
It is not possible to get the target entity or block from ProjectileHitEvent right now. There will be improvements in the future that enable this.
Yes, but that may not always be what you want. I am creating a pull request that adds ProjectileHitEntityEvent.
I know, you need to use instanceof to get the damager, projectile or the victim, but yeah a simple function would be always better
For now, I just check if the item in the shooter's hand is a bow. This might not always work because if the shooter changes their held item before the arrow hits the victim, it would return something else.
That's not the point. The point is, EntityDamageEvent was not related to projectiles in the first place. ProjectileHitEvent is otherwise worthless.