Player: Accept NBT data in constructor, instead of asking for it from the server directly

this allows custom implementations to provide custom data to the constructor (or none at all).
This commit is contained in:
Dylan K. Taylor 2020-07-09 13:09:46 +01:00
parent f2cf453cd0
commit b22cc4875e
2 changed files with 6 additions and 4 deletions

View File

@ -224,11 +224,15 @@ class NetworkSession{
$ev->call();
$class = $ev->getPlayerClass();
//TODO: make this async
//TODO: this really has no business being in NetworkSession at all - what about allowing it to be provided by PlayerCreationEvent?
$namedtag = $this->server->getOfflinePlayerData($this->info->getUsername());
/**
* @var Player $player
* @see Player::__construct()
*/
$this->player = new $class($this->server, $this, $this->info, $this->authenticated);
$this->player = new $class($this->server, $this, $this->info, $this->authenticated, $namedtag);
$this->invManager = new InventoryManager($this->player, $this);

View File

@ -263,7 +263,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
/** @var SurvivalBlockBreakHandler|null */
protected $blockBreakHandler = null;
public function __construct(Server $server, NetworkSession $session, PlayerInfo $playerInfo, bool $authenticated){
public function __construct(Server $server, NetworkSession $session, PlayerInfo $playerInfo, bool $authenticated, ?CompoundTag $namedtag){
$username = TextFormat::clean($playerInfo->getUsername());
$this->logger = new \PrefixedLogger($server->getLogger(), "Player: $username");
@ -284,8 +284,6 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$this->spawnThreshold = (int) (($this->server->getConfigGroup()->getProperty("chunk-sending.spawn-radius", 4) ** 2) * M_PI);
$this->chunkSelector = new ChunkSelector();
$namedtag = $this->server->getOfflinePlayerData($this->username); //TODO: make this async
if($namedtag !== null and ($world = $this->server->getWorldManager()->getWorldByName($namedtag->getString("Level", ""))) !== null){
$spawn = EntityDataHelper::parseLocation($namedtag, $world);
$onGround = $namedtag->getByte("OnGround", 1) === 1;