mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 01:09:44 +00:00
More cleanups to level provider hierarchy, move more garbage out of BaseLevelProvider
This commit is contained in:
parent
4f421d561c
commit
4d9d4d7c60
@ -48,7 +48,6 @@ use pocketmine\level\biome\Biome;
|
||||
use pocketmine\level\format\Chunk;
|
||||
use pocketmine\level\format\ChunkException;
|
||||
use pocketmine\level\format\EmptySubChunk;
|
||||
use pocketmine\level\format\io\BaseLevelProvider;
|
||||
use pocketmine\level\format\io\LevelProvider;
|
||||
use pocketmine\level\generator\Generator;
|
||||
use pocketmine\level\generator\GeneratorManager;
|
||||
@ -1025,9 +1024,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
|
||||
$this->provider->setTime($this->time);
|
||||
$this->saveChunks();
|
||||
if($this->provider instanceof BaseLevelProvider){
|
||||
$this->provider->saveLevelData();
|
||||
}
|
||||
$this->provider->saveLevelData();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -26,9 +26,7 @@ namespace pocketmine\level\format\io;
|
||||
use pocketmine\level\format\Chunk;
|
||||
use pocketmine\level\LevelException;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\BigEndianNBTStream;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\StringTag;
|
||||
|
||||
abstract class BaseLevelProvider implements LevelProvider{
|
||||
/** @var string */
|
||||
@ -46,32 +44,9 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
$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($levelDatPath));
|
||||
abstract protected function loadLevelData() : void;
|
||||
|
||||
if(!($levelData instanceof CompoundTag) or !$levelData->hasTag("Data", CompoundTag::class)){
|
||||
throw new LevelException("Invalid level.dat");
|
||||
}
|
||||
|
||||
$this->levelData = $levelData->getCompoundTag("Data");
|
||||
}
|
||||
|
||||
protected function fixLevelData() : void{
|
||||
if(!$this->levelData->hasTag("generatorName", StringTag::class)){
|
||||
$this->levelData->setString("generatorName", "default", true);
|
||||
}elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($this->levelData->getString("generatorName"))) !== null){
|
||||
$this->levelData->setString("generatorName", $generatorName);
|
||||
}
|
||||
|
||||
if(!$this->levelData->hasTag("generatorOptions", StringTag::class)){
|
||||
$this->levelData->setString("generatorOptions", "");
|
||||
}
|
||||
}
|
||||
abstract protected function fixLevelData() : void;
|
||||
|
||||
/**
|
||||
* Hack to fix worlds broken previously by older versions of PocketMine-MP which incorrectly saved classpaths of
|
||||
@ -137,10 +112,6 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
$this->levelData->setInt("SpawnZ", $pos->getFloorZ());
|
||||
}
|
||||
|
||||
public function doGarbageCollection(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CompoundTag
|
||||
*/
|
||||
@ -148,14 +119,6 @@ abstract class BaseLevelProvider implements LevelProvider{
|
||||
return $this->levelData;
|
||||
}
|
||||
|
||||
public function saveLevelData(){
|
||||
$nbt = new BigEndianNBTStream();
|
||||
$buffer = $nbt->writeCompressed(new CompoundTag("", [
|
||||
$this->levelData
|
||||
]));
|
||||
file_put_contents($this->getPath() . "level.dat", $buffer);
|
||||
}
|
||||
|
||||
public function loadChunk(int $chunkX, int $chunkZ) : ?Chunk{
|
||||
return $this->readChunk($chunkX, $chunkZ);
|
||||
}
|
||||
|
@ -194,6 +194,11 @@ interface LevelProvider{
|
||||
*/
|
||||
public function doGarbageCollection();
|
||||
|
||||
/**
|
||||
* Saves information about the level state, such as weather, time, etc.
|
||||
*/
|
||||
public function saveLevelData();
|
||||
|
||||
/**
|
||||
* Performs cleanups necessary when the level provider is closed and no longer needed.
|
||||
*/
|
||||
|
@ -532,6 +532,10 @@ class LevelDB extends BaseLevelProvider{
|
||||
return $this->db->get(LevelDB::chunkIndex($chunkX, $chunkZ) . self::TAG_VERSION) !== false;
|
||||
}
|
||||
|
||||
public function doGarbageCollection(){
|
||||
|
||||
}
|
||||
|
||||
public function close(){
|
||||
$this->db->close();
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ use pocketmine\level\format\Chunk;
|
||||
use pocketmine\level\format\io\BaseLevelProvider;
|
||||
use pocketmine\level\generator\GeneratorManager;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\level\LevelException;
|
||||
use pocketmine\nbt\BigEndianNBTStream;
|
||||
use pocketmine\nbt\tag\ByteTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
@ -109,6 +110,40 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
|
||||
/** @var RegionLoader[] */
|
||||
protected $regions = [];
|
||||
|
||||
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($levelDatPath));
|
||||
|
||||
if(!($levelData instanceof CompoundTag) or !$levelData->hasTag("Data", CompoundTag::class)){
|
||||
throw new LevelException("Invalid level.dat");
|
||||
}
|
||||
|
||||
$this->levelData = $levelData->getCompoundTag("Data");
|
||||
}
|
||||
|
||||
protected function fixLevelData() : void{
|
||||
if(!$this->levelData->hasTag("generatorName", StringTag::class)){
|
||||
$this->levelData->setString("generatorName", "default", true);
|
||||
}elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($this->levelData->getString("generatorName"))) !== null){
|
||||
$this->levelData->setString("generatorName", $generatorName);
|
||||
}
|
||||
|
||||
if(!$this->levelData->hasTag("generatorOptions", StringTag::class)){
|
||||
$this->levelData->setString("generatorOptions", "");
|
||||
}
|
||||
}
|
||||
|
||||
public function saveLevelData(){
|
||||
$nbt = new BigEndianNBTStream();
|
||||
$buffer = $nbt->writeCompressed(new CompoundTag("", [
|
||||
$this->levelData
|
||||
]));
|
||||
file_put_contents($this->getPath() . "level.dat", $buffer);
|
||||
}
|
||||
|
||||
public function getGenerator() : string{
|
||||
return $this->levelData->getString("generatorName", "DEFAULT");
|
||||
|
Loading…
x
Reference in New Issue
Block a user