BaseLevelProvider: clean up not-exists error handling disaster

It checks for the existence of (and creates) the world directory if it doesn't exist. But what sense does this make when the world obviously doesn't exist in this case and must be generated first?
This commit is contained in:
Dylan K. Taylor 2018-10-04 15:41:18 +01:00
parent f787552e97
commit 4f421d561c
2 changed files with 13 additions and 5 deletions

View File

@ -37,18 +37,22 @@ abstract class BaseLevelProvider implements LevelProvider{
protected $levelData;
public function __construct(string $path){
$this->path = $path;
if(!file_exists($this->path)){
mkdir($this->path, 0777, true);
if(!file_exists($path)){
throw new LevelException("Level does not exist");
}
$this->path = $path;
$this->loadLevelData();
$this->fixLevelData();
}
protected function loadLevelData() : void{
$levelDatPath = $this->getPath() . "level.dat";
if(!file_exists($levelDatPath)){
throw new LevelException("level.dat not found");
}
$nbt = new BigEndianNBTStream();
$levelData = $nbt->readCompressed(file_get_contents($this->getPath() . "level.dat"));
$levelData = $nbt->readCompressed(file_get_contents($levelDatPath));
if(!($levelData instanceof CompoundTag) or !$levelData->hasTag("Data", CompoundTag::class)){
throw new LevelException("Invalid level.dat");

View File

@ -100,8 +100,12 @@ class LevelDB extends BaseLevelProvider{
}
protected function loadLevelData() : void{
$levelDatPath = $this->getPath() . "level.dat";
if(!file_exists($levelDatPath)){
throw new LevelException("level.dat not found");
}
$nbt = new LittleEndianNBTStream();
$levelData = $nbt->read(substr(file_get_contents($this->getPath() . "level.dat"), 8));
$levelData = $nbt->read(substr(file_get_contents($levelDatPath), 8));
if($levelData instanceof CompoundTag){
$this->levelData = $levelData;
}else{