From 5a89e808731fa95a281ccc7e3b0671c0f29d1e0c Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 1 Mar 2018 09:09:34 +0000 Subject: [PATCH] Server: added getPlayerByUUID() and getPlayerByRawUUID() closes #2047 Since the player list already indexes players by UUID, it's simple to just use that for fetching the player. A possible future improvement could be to allow fetching an _offline_ player by UUID, but no capability to do that is yet available. --- src/pocketmine/Server.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index f5fead23f..5db1f7ad0 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -878,6 +878,28 @@ class Server{ return $matchedPlayers; } + /** + * Returns the player online with the specified raw UUID, or null if not found + * + * @param string $rawUUID + * + * @return null|Player + */ + public function getPlayerByRawUUID(string $rawUUID) : ?Player{ + return $this->playerList[$rawUUID] ?? null; + } + + /** + * Returns the player online with a UUID equivalent to the specified UUID object, or null if not found + * + * @param UUID $uuid + * + * @return null|Player + */ + public function getPlayerByUUID(UUID $uuid) : ?Player{ + return $this->getPlayerByRawUUID($uuid->toBinary()); + } + /** * @return Level[] */