So basically in a plugin I'm making called Mockingbird, I use the close() function to kick the player with a message. The player gets kicked, but the server crashes with the error: Code: [15:15:33] [Server thread/INFO]: coEthaniccc was removed from the game for the suspicion of using hacks in-game. They will be able to rejoin in 300 seconds. [15:15:33] [Server thread/CRITICAL]: Error: "Call to a member function getBlockAt() on null" (EXCEPTION) in "src/pocketmine/entity/Entity" at line 1474 I tried the same thing with kick(), but it crashed as well. I (now) know this isn't a Pocketmine issue because /ban works just fine. You can check all the code (if you have the time) here: https://github.com/ethaniccc/Mockingbird I have no idea why this is happening, so if you could help me that would be nice. (The only enabled detections at that time were Speed, I disabled the rest) Thanks in advance!
I used kick() and close(), but still got the same error Code: [15:15:33] [Server thread/CRITICAL]: Error: "Call to a member function getBlockAt() on null" (EXCEPTION) in "src/pocketmine/entity/Entity" at line 1474 PHP: public static function blockPlayer(Player $player){ $seconds = self::$blockedAddresses[$player->getAddress()]; $player->kick(TextFormat::BOLD . TextFormat::RED . "Mockingbird AntiCheat\n" . TextFormat::RESET . TextFormat::AQUA . "You were removed from the server for using cheats in-game.\nYou will be able to join back in $seconds seconds.\nIf this was an error, contact staff.", false); } It kicks the player with the message, but right after, the server crashes
Spoiler: Function at line 1474 of Entity.php PHP: public function isUnderwater() : bool{ $block = $this->level->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z)); if($block instanceof Water){ $f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111); return $y < $f; } return false; }
Code: [15:15:33] [Server thread/CRITICAL]: Error: "Call to a member function getBlockAt() on null" (EXCEPTION) in "src/pocketmine/entity/Entity" at line 1474 PHP: $block = $this->level->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z)); I think $this->level is null, is this bug happens when you teleport to another map?
Could be, but after actually getting some sleep I have a thought (I'm on my phone RN). Thinking back to my code, I realize that it closes the player before any check is complete, which is probably why it's giving that error, because it's still trying to call a function from that player even though it no longer exists on the server.
You should not kick the player during the event because most of the events rely on the player to continue, schedule a task to kick