diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index 92a41cf16..1ae81ff35 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -914,10 +914,15 @@ class NetworkSession{ ChunkCache::getInstance($world, $this->compressor)->request($chunkX, $chunkZ)->onResolve( //this callback may be called synchronously or asynchronously, depending on whether the promise is resolved yet - function(CompressBatchPromise $promise) use ($world, $onCompletion) : void{ + function(CompressBatchPromise $promise) use ($world, $onCompletion, $chunkX, $chunkZ) : void{ if(!$this->isConnected()){ return; } + $currentWorld = $this->player->getLocation()->getWorld(); + if($world !== $currentWorld or !$this->player->isUsingChunk($chunkX, $chunkZ)){ + $this->logger->debug("Tried to send no-longer-active chunk $chunkX $chunkZ in world " . $world->getFolderName()); + return; + } $world->timings->syncChunkSend->startTiming(); try{ $this->queueCompressed($promise); diff --git a/src/player/Player.php b/src/player/Player.php index 2350c3863..6d459b8d4 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -743,11 +743,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ unset($this->loadQueue[$index]); $this->usedChunks[$index] = UsedChunkStatus::REQUESTED(); - $this->getNetworkSession()->startUsingChunk($X, $Z, function() use ($X, $Z, $index, $world) : void{ - if(!isset($this->usedChunks[$index]) || $world !== $this->getWorld()){ - $this->logger->debug("Tried to send no-longer-active chunk $X $Z in world " . $world->getFolderName()); - return; - } + $this->getNetworkSession()->startUsingChunk($X, $Z, function() use ($X, $Z, $index) : void{ if(!$this->usedChunks[$index]->equals(UsedChunkStatus::REQUESTED())){ //TODO: make this an error //this could be triggered due to the shitty way that chunk resends are handled