level = $level; $this->path = $path; if(!file_exists($this->path)){ mkdir($this->path, 0777, true); } $nbt = new BigEndianNBTStream(); $nbt->readCompressed(file_get_contents($this->getPath() . "level.dat")); $levelData = $nbt->getData()->getCompoundTag("Data"); if($levelData !== null){ $this->levelData = $levelData; }else{ throw new LevelException("Invalid level.dat"); } if(!$this->levelData->hasTag("generatorName", StringTag::class)){ $this->levelData->setString("generatorName", (string) Generator::getGenerator("DEFAULT"), true); } if(!$this->levelData->hasTag("generatorOptions", StringTag::class)){ $this->levelData->setString("generatorOptions", ""); } } public function getPath() : string{ return $this->path; } public function getServer(){ return $this->level->getServer(); } public function getLevel() : Level{ return $this->level; } public function getName() : string{ return $this->levelData->getString("LevelName"); } public function getTime() : int{ return $this->levelData->getLong("Time", 0, true); } public function setTime(int $value){ $this->levelData->setLong("Time", $value, true); //some older PM worlds had this in the wrong format } public function getSeed() : int{ return $this->levelData->getLong("RandomSeed"); } public function setSeed(int $value){ $this->levelData->setLong("RandomSeed", $value); } public function getSpawn() : Vector3{ return new Vector3($this->levelData->getInt("SpawnX"), $this->levelData->getInt("SpawnY"), $this->levelData->getInt("SpawnZ")); } public function setSpawn(Vector3 $pos){ $this->levelData->setInt("SpawnX", (int) $pos->x); $this->levelData->setInt("SpawnY", (int) $pos->y); $this->levelData->setInt("SpawnZ", (int) $pos->z); } public function doGarbageCollection(){ } /** * @return CompoundTag */ public function getLevelData() : CompoundTag{ return $this->levelData; } public function saveLevelData(){ $nbt = new BigEndianNBTStream(); $nbt->setData(new CompoundTag("", [ $this->levelData ])); $buffer = $nbt->writeCompressed(); file_put_contents($this->getPath() . "level.dat", $buffer); } }