Allow offline player data to be provided from a custom source

This commit is contained in:
Dylan K. Taylor 2021-02-07 20:29:37 +00:00
parent 7745310870
commit c05779314d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 7 additions and 7 deletions

View File

@ -576,20 +576,16 @@ class Server{
}
}
public function createPlayer(NetworkSession $session, PlayerInfo $playerInfo, bool $authenticated) : Player{
public function createPlayer(NetworkSession $session, PlayerInfo $playerInfo, bool $authenticated, ?CompoundTag $offlinePlayerData) : Player{
$ev = new PlayerCreationEvent($session);
$ev->call();
$class = $ev->getPlayerClass();
//TODO: make this async
//TODO: what about allowing this to be provided by PlayerCreationEvent?
$namedtag = $this->getOfflinePlayerData($playerInfo->getUsername());
/**
* @see Player::__construct()
* @var Player $player
*/
$player = new $class($this, $session, $playerInfo, $authenticated, $namedtag);
$player = new $class($this, $session, $playerInfo, $authenticated, $offlinePlayerData);
return $player;
}

View File

@ -229,7 +229,11 @@ class NetworkSession{
}
protected function createPlayer() : void{
$this->player = $this->server->createPlayer($this, $this->info, $this->authenticated);
//TODO: make this async
//TODO: what about allowing this to be provided by PlayerCreationEvent?
$offlinePlayerData = $this->server->getOfflinePlayerData($this->info->getUsername());
$this->player = $this->server->createPlayer($this, $this->info, $this->authenticated, $offlinePlayerData);
$this->invManager = new InventoryManager($this->player, $this);