mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +00:00
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:
parent
f2cf453cd0
commit
b22cc4875e
@ -224,11 +224,15 @@ class NetworkSession{
|
|||||||
$ev->call();
|
$ev->call();
|
||||||
$class = $ev->getPlayerClass();
|
$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
|
* @var Player $player
|
||||||
* @see Player::__construct()
|
* @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);
|
$this->invManager = new InventoryManager($this->player, $this);
|
||||||
|
|
||||||
|
@ -263,7 +263,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
/** @var SurvivalBlockBreakHandler|null */
|
/** @var SurvivalBlockBreakHandler|null */
|
||||||
protected $blockBreakHandler = 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());
|
$username = TextFormat::clean($playerInfo->getUsername());
|
||||||
$this->logger = new \PrefixedLogger($server->getLogger(), "Player: $username");
|
$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->spawnThreshold = (int) (($this->server->getConfigGroup()->getProperty("chunk-sending.spawn-radius", 4) ** 2) * M_PI);
|
||||||
$this->chunkSelector = new ChunkSelector();
|
$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){
|
if($namedtag !== null and ($world = $this->server->getWorldManager()->getWorldByName($namedtag->getString("Level", ""))) !== null){
|
||||||
$spawn = EntityDataHelper::parseLocation($namedtag, $world);
|
$spawn = EntityDataHelper::parseLocation($namedtag, $world);
|
||||||
$onGround = $namedtag->getByte("OnGround", 1) === 1;
|
$onGround = $namedtag->getByte("OnGround", 1) === 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user