When I use this code PHP: public function onPlayerHurt(EntityDamageEvent $event){ $entity = $event->getEntity(); if(($entity instanceof Player) && $entity->getPlayer()->getLevel()->getName() == $this->getConfig()->get("SpawnWorld")) { $event->setCancelled(); } if(isset($this->gamePlayers[$entity->getPlayer()->getName()])) { //<--- Line 919 $event->setCancelled(); } } I get this error and it crashes the server when a player joins...help please. Code: Fatal error: Call to undefined method pocketmine\entity\Item::getPlayer() in C:\Users\Crispeh\Downloads\PocketMine-MP\plugins\bh\src\BlockHunt\Main.php on line 919
It is $entity not $entity->getPlayer()... If you need I check whether it is a player, use if($entity instanceof Player). Who taught you to do that...
Ohhh my bad aha thanks, I thought it was like this for some reason. Also, PHP: if(($entity instanceof Player) && $entity->getPlayer()->getLevel()->getName() == $this->getConfig()->get("SpawnWorld")) { //I CHECK HERE!}
Ok now im getting Code: Fatal error: Call to undefined method pocketmine\entity\Item::getName() in C:\Users\Crispeh\Downloads\PocketMine-MP\plugins\bh\src\BlockHunt\Main.php on line 941 And I removed ->getPlayer() :/. I think this is a bug in pocketmine
PHP: public function onPlayerHurt(EntityDamageEvent $event){ $entity = $event->getEntity(); if(!($entity instanceof Player)) { return; } if($entity->getLevel()->getName() == $this->getConfig()->get("SpawnWorld")) { $event->setCancelled(); } if(isset($this->gamePlayers[$entity->getName()])) { $event->setCancelled(); } }
I just copy/pasted what he had and edited it. I missed that one. I fixed it now. It technically still would have worked, as the Player object has a getPlayer function that returns itself, and by that point in his code, the entity was already confirmed as a player.