Try this on interactevent: PHP: $player = $event->getPlayer(); $item = $player->getInventory()->getItemInHand()->getId(); if ($item === 345) { $closest = "nullbody"; $lastSquare = -1; foreach ($player->getLevel()->getPlayers() as $p) { if ($p !== $player) { $x = $p->x - $player->x; $z = $p->z - $player->z; $square = abs($x) + abs($z); if ($lastSquare === -1 or $lastSquare > $square) { $closest = $p->getName(); $lastSquare = round($square); } } } $player->sendPopup("Closest player is " . $closest); // fyi i didnt test this