From d5faaf57ffb5e15a320e3c48496ada99699a473c Mon Sep 17 00:00:00 2001 From: beu Date: Sat, 12 Mar 2022 19:34:39 +0100 Subject: [PATCH] Load the author nickname of a map when the author is known --- core/Maps/Map.php | 18 ++++++++++++++++-- core/Maps/MapManager.php | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/core/Maps/Map.php b/core/Maps/Map.php index 0e8a8b38..2022290f 100644 --- a/core/Maps/Map.php +++ b/core/Maps/Map.php @@ -8,6 +8,8 @@ use ManiaControl\General\UsageInformationAble; use ManiaControl\General\UsageInformationTrait; use ManiaControl\ManiaExchange\MXMapInfo; use ManiaControl\Utils\Formatter; +use ManiaControl\ManiaControl; +use ManiaControl\Players\Player; /** * ManiaControl Map Model Class @@ -52,12 +54,19 @@ class Map implements Dumpable, UsageInformationAble { public $lastUpdate = 0; public $karma = null; + /* + * Private properties + */ + /** @var ManiaControl $maniaControl */ + private $maniaControl = null; + /** * Construct a new map instance from xmlrpc data * * @param \Maniaplanet\DedicatedServer\Structures\Map $mpMap */ - public function __construct($mpMap = null) { + public function __construct(ManiaControl $maniaControl, $mpMap = null) { + $this->maniaControl = $maniaControl; $this->startTime = time(); if (!$mpMap) { @@ -79,7 +88,12 @@ class Map implements Dumpable, UsageInformationAble { $this->nbCheckpoints = $mpMap->nbCheckpoints; $this->nbLaps = $mpMap->nbLaps; - $this->authorNick = $this->authorLogin; + $player = $this->maniaControl->getPlayerManager()->getPlayer($this->authorLogin); + if ($player) { + $this->authorNick = $player->nickname; + } else { + $this->authorNick = $this->authorLogin; + } } /** diff --git a/core/Maps/MapManager.php b/core/Maps/MapManager.php index 3aabcb1a..b31e0446 100644 --- a/core/Maps/MapManager.php +++ b/core/Maps/MapManager.php @@ -595,7 +595,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform * @return Map */ public function initializeMap($rpcMap) { - $map = new Map($rpcMap); + $map = new Map($this->maniaControl, $rpcMap); $this->saveMap($map); return $map; }