Code: <?php namespace _64FF00\SOMETHINGUSELESS; use pocketmine\level\Location; use pocketmine\Player; use pocketmine\plugin\PluginBase; class SOMETHINGUSELESS extends PluginBase { // ... public function getNearestPlayer(Player $player) { $playerLocation = $player->getLocation(); $targetPlayers = $this->getServer()->getOnlinePlayers(); $nearestDistance = 0; foreach($targetPlayers as $targetPlayer) { $targetLocation = $target->getLocation(); if($nearestDistance == 0 || $playerLocation->distance($targetLocation) < $nearestDistance) { $nearestDistance = $playerLocation->distance($targetLocation); $nearestPlayer = $targetPlayer; } } return $nearestPlayer; } // ... } ... though I might be wrong.