From 3455d0f3b9e3a615af322fd5eeb448e33e353768 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 29 Jun 2018 10:58:31 +0100 Subject: [PATCH 1/4] Level: cleaned up some nonsensical code in setChunk() --- src/pocketmine/level/Level.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 8fcddabd9..65cd4e0af 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -2346,21 +2346,20 @@ class Level implements ChunkManager, Metadatable{ $chunkHash = Level::chunkHash($chunkX, $chunkZ); $oldChunk = $this->getChunk($chunkX, $chunkZ, false); - if($unload and $oldChunk !== null){ - $this->unloadChunk($chunkX, $chunkZ, false, false); - }else{ - $oldEntities = $oldChunk !== null ? $oldChunk->getEntities() : []; - $oldTiles = $oldChunk !== null ? $oldChunk->getTiles() : []; + if($oldChunk !== null){ + if($unload){ + $this->unloadChunk($chunkX, $chunkZ, false, false); + }else{ + foreach($oldChunk->getEntities() as $entity){ + $chunk->addEntity($entity); + $oldChunk->removeEntity($entity); + $entity->chunk = $chunk; + } - foreach($oldEntities as $entity){ - $chunk->addEntity($entity); - $oldChunk->removeEntity($entity); - $entity->chunk = $chunk; - } - - foreach($oldTiles as $tile){ - $chunk->addTile($tile); - $oldChunk->removeTile($tile); + foreach($oldChunk->getTiles() as $tile){ + $chunk->addTile($tile); + $oldChunk->removeTile($tile); + } } } From d8824e7ee1639138654828dfc089f3b006faa2b9 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 29 Jun 2018 11:06:33 +0100 Subject: [PATCH 2/4] Level: discard changed blocks on chunk replace this could cause issues when plugins replace chunks when blocks in the chunk have been changed on the same tick. --- src/pocketmine/level/Level.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 65cd4e0af..d1266d28b 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -2367,6 +2367,7 @@ class Level implements ChunkManager, Metadatable{ unset($this->blockCache[$chunkHash]); unset($this->chunkCache[$chunkHash]); + unset($this->changedBlocks[$chunkHash]); $chunk->setChanged(); if(!$this->isChunkInUse($chunkX, $chunkZ)){ From 57cfe9fd434112bc74f3c0a2a8d9959239d52bfd Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 29 Jun 2018 11:10:31 +0100 Subject: [PATCH 3/4] Level: fixed logic for sending changed blocks to players If there is an empty list of blocks in the changedBlocks array for a chunk, that means that blocks changed the normal way and then were later set the direct way in the same tick. This means that no action needs to be taken on these chunks. --- src/pocketmine/level/Level.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index d1266d28b..b8a6fc9e2 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -769,6 +769,9 @@ class Level implements ChunkManager, Metadatable{ if(count($this->changedBlocks) > 0){ if(count($this->players) > 0){ foreach($this->changedBlocks as $index => $blocks){ + if(empty($blocks)){ //blocks can be set normally and then later re-set with direct send + continue; + } unset($this->chunkCache[$index]); Level::getXZ($index, $chunkX, $chunkZ); if(count($blocks) > 512){ @@ -776,7 +779,7 @@ class Level implements ChunkManager, Metadatable{ foreach($this->getChunkPlayers($chunkX, $chunkZ) as $p){ $p->onChunkChanged($chunk); } - }elseif(!empty($blocks)){ + }else{ $this->sendBlocks($this->getChunkPlayers($chunkX, $chunkZ), $blocks, UpdateBlockPacket::FLAG_ALL); } } From c43ce5c8fad6eab12535b4d898859d8d155a760b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 29 Jun 2018 12:16:17 +0100 Subject: [PATCH 4/4] RCONInstance: apply stfu operator --- src/pocketmine/network/rcon/RCONInstance.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/network/rcon/RCONInstance.php b/src/pocketmine/network/rcon/RCONInstance.php index 570fda9f9..d1e98da2e 100644 --- a/src/pocketmine/network/rcon/RCONInstance.php +++ b/src/pocketmine/network/rcon/RCONInstance.php @@ -80,7 +80,7 @@ class RCONInstance extends Thread{ } private function readPacket($client, ?int &$requestID, ?int &$packetType, ?string &$payload){ - $d = socket_read($client, 4); + $d = @socket_read($client, 4); if($this->stop){ return false; }elseif($d === false){