mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-18 03:35:33 +00:00
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:
parent
f787552e97
commit
4f421d561c
@ -37,18 +37,22 @@ abstract class BaseLevelProvider implements LevelProvider{
|
|||||||
protected $levelData;
|
protected $levelData;
|
||||||
|
|
||||||
public function __construct(string $path){
|
public function __construct(string $path){
|
||||||
$this->path = $path;
|
if(!file_exists($path)){
|
||||||
if(!file_exists($this->path)){
|
throw new LevelException("Level does not exist");
|
||||||
mkdir($this->path, 0777, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->path = $path;
|
||||||
$this->loadLevelData();
|
$this->loadLevelData();
|
||||||
$this->fixLevelData();
|
$this->fixLevelData();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadLevelData() : void{
|
protected function loadLevelData() : void{
|
||||||
|
$levelDatPath = $this->getPath() . "level.dat";
|
||||||
|
if(!file_exists($levelDatPath)){
|
||||||
|
throw new LevelException("level.dat not found");
|
||||||
|
}
|
||||||
$nbt = new BigEndianNBTStream();
|
$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)){
|
if(!($levelData instanceof CompoundTag) or !$levelData->hasTag("Data", CompoundTag::class)){
|
||||||
throw new LevelException("Invalid level.dat");
|
throw new LevelException("Invalid level.dat");
|
||||||
|
@ -100,8 +100,12 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function loadLevelData() : void{
|
protected function loadLevelData() : void{
|
||||||
|
$levelDatPath = $this->getPath() . "level.dat";
|
||||||
|
if(!file_exists($levelDatPath)){
|
||||||
|
throw new LevelException("level.dat not found");
|
||||||
|
}
|
||||||
$nbt = new LittleEndianNBTStream();
|
$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){
|
if($levelData instanceof CompoundTag){
|
||||||
$this->levelData = $levelData;
|
$this->levelData = $levelData;
|
||||||
}else{
|
}else{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user