I'm making an area plugin which shouldn't allow players that are on combat to throw ender pearls at a designated area. I've thought about using EntityMotionEvent but I'm not sure how to get the player.
Code: public function enderpearlLaunchEvent(ProjectileLaunchEvent $event){ $entity = $event->getEntity(); if ($entity instanceof EnderPearl){ $event->setCancelled(true); } } easy man
PHP: public function enderpearlLauncheEvent(ProjectileLaunchEvent $event){ $entity = $event->getEntity(); if ($entity instanceof EnderPearl){ $player = $entity->getOwningEntity(); //this can return null, check that isn't null before using it if ($player instanceof Player and $player !== null) { $this->getLogger()->info("This player have launch and enderpearl: " . $player->getName()); } } } use getOwningEntity() and getTargetEntity()
Btw $player instanceof Player implies $player is not null so the $player !== null check is not necessary.