seal up resource pack completion callback visibility

This commit is contained in:
Dylan K. Taylor 2020-04-25 03:31:13 +01:00
parent 6dd31cc3f5
commit 80680f15f4
2 changed files with 15 additions and 4 deletions

View File

@ -565,10 +565,12 @@ class NetworkSession{
$this->sendDataPacket(PlayStatusPacket::create(PlayStatusPacket::LOGIN_SUCCESS));
$this->logger->debug("Initiating resource packs phase");
$this->setHandler(new ResourcePacksPacketHandler($this, $this->server->getResourcePackManager()));
$this->setHandler(new ResourcePacksPacketHandler($this, $this->server->getResourcePackManager(), function() : void{
$this->onResourcePacksDone();
}));
}
public function onResourcePacksDone() : void{
private function onResourcePacksDone() : void{
$this->createPlayer();
$this->setHandler(new PreSpawnPacketHandler($this->server, $this->player, $this));

View File

@ -53,13 +53,22 @@ class ResourcePacksPacketHandler extends PacketHandler{
private $session;
/** @var ResourcePackManager */
private $resourcePackManager;
/**
* @var \Closure
* @phpstan-var \Closure() : void
*/
private $completionCallback;
/** @var bool[][] uuid => [chunk index => hasSent] */
private $downloadedChunks = [];
public function __construct(NetworkSession $session, ResourcePackManager $resourcePackManager){
/**
* @phpstan-param \Closure() : void $completionCallback
*/
public function __construct(NetworkSession $session, ResourcePackManager $resourcePackManager, \Closure $completionCallback){
$this->session = $session;
$this->resourcePackManager = $resourcePackManager;
$this->completionCallback = $completionCallback;
}
public function setUp() : void{
@ -124,7 +133,7 @@ class ResourcePacksPacketHandler extends PacketHandler{
break;
case ResourcePackClientResponsePacket::STATUS_COMPLETED:
$this->session->getLogger()->debug("Resource packs sequence completed");
$this->session->onResourcePacksDone();
($this->completionCallback)();
break;
default:
return false;