PHP: public function onPlayerTeleport (EntityTeleportEvent $event) { if ($event->getEntity() instanceof Player) { $world = $event->getTo()->getLevel()->getName(); } } After the most resent release it started throwing error "getName() on null" when a Player joins ,is this an issue since release 3.6.5 didn't throw such errors? Or am I mis-understanding things
3.6.5 and 3.7.0 are functionally identical, as stated by the release notes. Regardless of the cause, you haven't provided sufficient information for anyone to help you.
Okay so I haven't tested it on without any other code but still the code provided above shouldn't be affected by anything as it's an Event called by the Server itself. The event is registered and I don't know if intentional or not it is called when a player joins the server. It then throws getName() on null and crashes. getTo() doesn't have level for some reason
Alright here is the code that magically makes the level null: Solution on the bottom of the snippet: PHP: class Main extends \pocketmine\plugin\PluginBase implements \pocketmine\event\Listener { public $defaultSpawn; public function onEnable () { $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getScheduler()->scheduleDelayedTask(new Task($this), 60); } public function onPlayerLogin (\pocketmine\event\player\PlayerLoginEvent $player_login_event) { $player_login_event->getPlayer()->teleport($this->defaultSpawn); } public function onPlayerTeleport (\pocketmine\event\entity\EntityTeleportEvent $event) { if ($event->getEntity() instanceof \pocketmine\Player) { $this->getLogger()->debug(print_r($event->getTo())); $this->getLogger()->debug(print_r($event->getTo()->getLevel())); $this->getLogger()->debug(print_r($event->getTo()->getLevel()->getName())); } } } class Task extends \pocketmine\scheduler\Task { private $main; public function __construct (Main $main) { $this->main = $main; } public function onRun (int $currentTick) { $defaultSpawn = $this->main->getServer()->getDefaultLevel()->getSafeSpawn(); $this->main->defaultSpawn = new \pocketmine\level\Position($defaultSpawn->getX() - 0.5, $defaultSpawn->getY(),$defaultSpawn->getZ() - 0.5,$defaultSpawn->getLevel());//$defaultSpawn->getLevel() wasn't specified so getTo() in EntityTeleportEvent was receiving null } } What did I do wrong? @dktapps
It is after 60 ticks um 3 seconds I think and the error occurs in the EntityTeleportEvent function which I named playerTeleportEvent. Then again the function itself has nothing to do with $main->defaultSpawn Edit: It wasn't specified I'm sorry, and yes that fixed my issue. Now I understand what was going on....And I feel dumb