RegionLoader: Stop unnecessarily writing location header on close

Any time a region is modified, the location header is written anyway, so this is entirely unnecessary.
This commit is contained in:
Dylan K. Taylor 2019-03-14 15:06:13 +00:00
parent d080d3bae0
commit 1e0f1e5b1a
2 changed files with 3 additions and 24 deletions

View File

@ -148,7 +148,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
$logger = \GlobalLogger::get();
$logger->error("Corrupted region file detected: " . $e->getMessage());
$region->close(false); //Do not write anything to the file
$region->close(); //Do not write anything to the file
$backupPath = $path . ".bak." . time();
rename($path, $backupPath);

View File

@ -40,7 +40,6 @@ use function fwrite;
use function is_resource;
use function max;
use function ord;
use function pack;
use function str_pad;
use function stream_set_read_buffer;
use function stream_set_write_buffer;
@ -102,7 +101,6 @@ class RegionLoader{
public function __destruct(){
if(is_resource($this->filePointer)){
$this->writeLocationTable();
fclose($this->filePointer);
}
}
@ -244,16 +242,10 @@ class RegionLoader{
}
/**
* Writes the region header and closes the file
*
* @param bool $writeHeader
* Closes the file
*/
public function close(bool $writeHeader = true) : void{
public function close() : void{
if(is_resource($this->filePointer)){
if($writeHeader){
$this->writeLocationTable();
}
fclose($this->filePointer);
}
}
@ -320,19 +312,6 @@ class RegionLoader{
}
}
private function writeLocationTable() : void{
$write = [];
for($i = 0; $i < 1024; ++$i){
$write[] = (($this->locationTable[$i]->getFirstSector() << 8) | $this->locationTable[$i]->getSectorCount());
}
for($i = 0; $i < 1024; ++$i){
$write[] = $this->locationTable[$i]->getTimestamp();
}
fseek($this->filePointer, 0);
fwrite($this->filePointer, pack("N*", ...$write), 4096 * 2);
}
protected function writeLocationIndex(int $index) : void{
fseek($this->filePointer, $index << 2);
fwrite($this->filePointer, Binary::writeInt(($this->locationTable[$index]->getFirstSector() << 8) | $this->locationTable[$index]->getSectorCount()), 4);