diff --git a/build/make-release.php b/build/make-release.php index 98f103dee..c9b0a0f2e 100644 --- a/build/make-release.php +++ b/build/make-release.php @@ -25,7 +25,6 @@ namespace pocketmine\build\make_release; use pocketmine\utils\VersionString; use pocketmine\VersionInfo; -use function defined; use function dirname; use function fgets; use function file_get_contents; @@ -86,6 +85,4 @@ function main(array $argv) : void{ system('git push origin HEAD ' . $currentVer->getBaseVersion()); } -if(!defined('pocketmine\_PHPSTAN_ANALYSIS')){ - main($argv); -} +main($argv); diff --git a/build/server-phar.php b/build/server-phar.php index ea8fd273d..cb3bc0888 100644 --- a/build/server-phar.php +++ b/build/server-phar.php @@ -26,7 +26,6 @@ namespace pocketmine\build\server_phar; use pocketmine\utils\Git; use function array_map; use function count; -use function defined; use function dirname; use function file_exists; use function getcwd; @@ -175,6 +174,4 @@ STUB } } -if(!defined('pocketmine\_PHPSTAN_ANALYSIS')){ - main(); -} +main(); diff --git a/src/PocketMine.php b/src/PocketMine.php index 92de3ca2e..857256990 100644 --- a/src/PocketMine.php +++ b/src/PocketMine.php @@ -267,7 +267,5 @@ namespace pocketmine { exit($exitCode); } - if(!defined('pocketmine\_PHPSTAN_ANALYSIS')){ - \pocketmine\server(); - } + \pocketmine\server(); } diff --git a/src/world/format/io/region/RegionLoader.php b/src/world/format/io/region/RegionLoader.php index 4851b9f57..c3c2ae18c 100644 --- a/src/world/format/io/region/RegionLoader.php +++ b/src/world/format/io/region/RegionLoader.php @@ -149,10 +149,7 @@ class RegionLoader{ } if($length > ($this->locationTable[$index]->getSectorCount() << 12)){ //Invalid chunk, bigger than defined number of sectors - \GlobalLogger::get()->error("Chunk x=$x,z=$z length mismatch (expected " . ($this->locationTable[$index]->getSectorCount() << 12) . " sectors, got $length sectors)"); - $old = $this->locationTable[$index]; - $this->locationTable[$index] = new RegionLocationTableEntry($old->getFirstSector(), $length >> 12, time()); - $this->writeLocationIndex($index); + throw new CorruptedChunkException("Chunk length mismatch (expected " . ($this->locationTable[$index]->getSectorCount() << 12) . " sectors, got $length sectors)"); } $chunkData = fread($this->filePointer, $length); @@ -175,6 +172,23 @@ class RegionLoader{ return $this->isChunkGenerated(self::getChunkOffset($x, $z)); } + private function disposeGarbageArea(RegionLocationTableEntry $oldLocation) : void{ + /* release the area containing the old copy to the garbage pool */ + $this->garbageTable->add($oldLocation); + + $endGarbage = $this->garbageTable->end(); + $nextSector = $this->nextSector; + for(; $endGarbage !== null and $endGarbage->getLastSector() + 1 === $nextSector; $endGarbage = $this->garbageTable->end()){ + $nextSector = $endGarbage->getFirstSector(); + $this->garbageTable->remove($endGarbage); + } + + if($nextSector !== $this->nextSector){ + $this->nextSector = $nextSector; + ftruncate($this->filePointer, $this->nextSector << 12); + } + } + /** * @throws ChunkException * @throws \InvalidArgumentException @@ -218,20 +232,7 @@ class RegionLoader{ $this->writeLocationIndex($index); if($oldLocation !== null){ - /* release the area containing the old copy to the garbage pool */ - $this->garbageTable->add($oldLocation); - - $endGarbage = $this->garbageTable->end(); - $nextSector = $this->nextSector; - for(; $endGarbage !== null and $endGarbage->getLastSector() + 1 === $nextSector; $endGarbage = $this->garbageTable->end()){ - $nextSector = $endGarbage->getFirstSector(); - $this->garbageTable->remove($endGarbage); - } - - if($nextSector !== $this->nextSector){ - $this->nextSector = $nextSector; - ftruncate($this->filePointer, $this->nextSector << 12); - } + $this->disposeGarbageArea($oldLocation); } } @@ -240,8 +241,12 @@ class RegionLoader{ */ public function removeChunk(int $x, int $z) : void{ $index = self::getChunkOffset($x, $z); + $oldLocation = $this->locationTable[$index]; $this->locationTable[$index] = null; $this->writeLocationIndex($index); + if($oldLocation !== null){ + $this->disposeGarbageArea($oldLocation); + } } /** diff --git a/tests/phpstan/bootstrap.php b/tests/phpstan/bootstrap.php index 9e514ffc5..ba8ccd3fc 100644 --- a/tests/phpstan/bootstrap.php +++ b/tests/phpstan/bootstrap.php @@ -21,8 +21,6 @@ declare(strict_types=1); -define('pocketmine\_PHPSTAN_ANALYSIS', true); - if(!defined('LEVELDB_ZLIB_RAW_COMPRESSION')){ //leveldb might not be loaded define('LEVELDB_ZLIB_RAW_COMPRESSION', 4);