mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
McRegion: Added method pathToRegion()
This commit is contained in:
parent
66e475cbb8
commit
7264ce43ae
@ -434,13 +434,26 @@ class McRegion extends BaseLevelProvider{
|
||||
return $this->regions[Level::chunkHash($regionX, $regionZ)] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to a specific region file based on its X/Z coordinates
|
||||
*
|
||||
* @param int $regionX
|
||||
* @param int $regionZ
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function pathToRegion(int $regionX, int $regionZ) : string{
|
||||
return $this->path . "region/r.$regionX.$regionZ." . static::REGION_FILE_EXTENSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $regionX
|
||||
* @param int $regionZ
|
||||
*/
|
||||
protected function loadRegion(int $regionX, int $regionZ){
|
||||
if(!isset($this->regions[$index = Level::chunkHash($regionX, $regionZ)])){
|
||||
$this->regions[$index] = new RegionLoader($this->getPath() . "region/r.$regionX.$regionZ." . static::REGION_FILE_EXTENSION, $regionX, $regionZ);
|
||||
$path = $this->pathToRegion($regionX, $regionZ);
|
||||
$this->regions[$index] = new RegionLoader($path, $regionX, $regionZ);
|
||||
try{
|
||||
$this->regions[$index]->open();
|
||||
}catch(CorruptedRegionException $e){
|
||||
@ -449,12 +462,11 @@ class McRegion extends BaseLevelProvider{
|
||||
|
||||
$this->regions[$index]->close(false); //Do not write anything to the file
|
||||
|
||||
$path = $this->regions[$index]->getFilePath();
|
||||
$backupPath = $path . ".bak." . time();
|
||||
rename($path, $backupPath);
|
||||
$logger->error("Corrupted region file has been backed up to " . $backupPath);
|
||||
|
||||
$this->regions[$index] = new RegionLoader($this->getPath() . "region/r.$regionX.$regionZ." . static::REGION_FILE_EXTENSION, $regionX, $regionZ);
|
||||
$this->regions[$index] = new RegionLoader($path, $regionX, $regionZ);
|
||||
$this->regions[$index]->open(); //this will create a new empty region to replace the corrupted one
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user