mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-25 12:54:03 +00:00
Move generator classpath hack out of BaseLevelProvider
This commit is contained in:
parent
49e47edcf5
commit
0cc4bc48cc
@ -43,36 +43,6 @@ abstract class BaseLevelProvider implements LevelProvider{
|
|||||||
|
|
||||||
abstract protected function loadLevelData() : LevelData;
|
abstract protected function loadLevelData() : LevelData;
|
||||||
|
|
||||||
/**
|
|
||||||
* Hack to fix worlds broken previously by older versions of PocketMine-MP which incorrectly saved classpaths of
|
|
||||||
* generators into level.dat on imported (not generated) worlds.
|
|
||||||
*
|
|
||||||
* This should only have affected leveldb worlds as far as I know, because PC format worlds include the
|
|
||||||
* generatorName tag by default. However, MCPE leveldb ones didn't, and so they would get filled in with something
|
|
||||||
* broken.
|
|
||||||
*
|
|
||||||
* This bug took a long time to get found because previously the generator manager would just return the default
|
|
||||||
* generator silently on failure to identify the correct generator, which caused lots of unexpected bugs.
|
|
||||||
*
|
|
||||||
* Only classnames which were written into the level.dat from "fixing" the level data are included here. These are
|
|
||||||
* hardcoded to avoid problems fixing broken worlds in the future if these classes get moved, renamed or removed.
|
|
||||||
*
|
|
||||||
* @param string $className Classname saved in level.dat
|
|
||||||
*
|
|
||||||
* @return null|string Name of the correct generator to replace the broken value
|
|
||||||
*/
|
|
||||||
public static function hackyFixForGeneratorClasspathInLevelDat(string $className) : ?string{
|
|
||||||
//THESE ARE DELIBERATELY HARDCODED, DO NOT CHANGE!
|
|
||||||
switch($className){
|
|
||||||
case 'pocketmine\level\generator\normal\Normal':
|
|
||||||
return "normal";
|
|
||||||
case 'pocketmine\level\generator\Flat':
|
|
||||||
return "flat";
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getPath() : string{
|
public function getPath() : string{
|
||||||
return $this->path;
|
return $this->path;
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,39 @@ abstract class BaseNbtLevelData implements LevelData{
|
|||||||
*/
|
*/
|
||||||
abstract protected function load() : ?CompoundTag;
|
abstract protected function load() : ?CompoundTag;
|
||||||
|
|
||||||
|
|
||||||
abstract protected function fix() : void;
|
abstract protected function fix() : void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hack to fix worlds broken previously by older versions of PocketMine-MP which incorrectly saved classpaths of
|
||||||
|
* generators into level.dat on imported (not generated) worlds.
|
||||||
|
*
|
||||||
|
* This should only have affected leveldb worlds as far as I know, because PC format worlds include the
|
||||||
|
* generatorName tag by default. However, MCPE leveldb ones didn't, and so they would get filled in with something
|
||||||
|
* broken.
|
||||||
|
*
|
||||||
|
* This bug took a long time to get found because previously the generator manager would just return the default
|
||||||
|
* generator silently on failure to identify the correct generator, which caused lots of unexpected bugs.
|
||||||
|
*
|
||||||
|
* Only classnames which were written into the level.dat from "fixing" the level data are included here. These are
|
||||||
|
* hardcoded to avoid problems fixing broken worlds in the future if these classes get moved, renamed or removed.
|
||||||
|
*
|
||||||
|
* @param string $className Classname saved in level.dat
|
||||||
|
*
|
||||||
|
* @return null|string Name of the correct generator to replace the broken value
|
||||||
|
*/
|
||||||
|
protected static function hackyFixForGeneratorClasspathInLevelDat(string $className) : ?string{
|
||||||
|
//THESE ARE DELIBERATELY HARDCODED, DO NOT CHANGE!
|
||||||
|
switch($className){
|
||||||
|
case 'pocketmine\level\generator\normal\Normal':
|
||||||
|
return "normal";
|
||||||
|
case 'pocketmine\level\generator\Flat':
|
||||||
|
return "flat";
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public function getCompoundTag() : CompoundTag{
|
public function getCompoundTag() : CompoundTag{
|
||||||
return $this->compoundTag;
|
return $this->compoundTag;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\level\format\io\data;
|
namespace pocketmine\level\format\io\data;
|
||||||
|
|
||||||
use pocketmine\level\format\io\BaseLevelProvider;
|
|
||||||
use pocketmine\level\generator\Flat;
|
use pocketmine\level\generator\Flat;
|
||||||
use pocketmine\level\generator\GeneratorManager;
|
use pocketmine\level\generator\GeneratorManager;
|
||||||
use pocketmine\level\Level;
|
use pocketmine\level\Level;
|
||||||
@ -133,7 +132,7 @@ class BedrockLevelData extends BaseNbtLevelData{
|
|||||||
}else{
|
}else{
|
||||||
$this->compoundTag->setString("generatorName", "default");
|
$this->compoundTag->setString("generatorName", "default");
|
||||||
}
|
}
|
||||||
}elseif(($generatorName = BaseLevelProvider::hackyFixForGeneratorClasspathInLevelDat($this->compoundTag->getString("generatorName"))) !== null){
|
}elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($this->compoundTag->getString("generatorName"))) !== null){
|
||||||
$this->compoundTag->setString("generatorName", $generatorName);
|
$this->compoundTag->setString("generatorName", $generatorName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\level\format\io\data;
|
namespace pocketmine\level\format\io\data;
|
||||||
|
|
||||||
use pocketmine\level\format\io\BaseLevelProvider;
|
|
||||||
use pocketmine\level\generator\GeneratorManager;
|
use pocketmine\level\generator\GeneratorManager;
|
||||||
use pocketmine\level\Level;
|
use pocketmine\level\Level;
|
||||||
use pocketmine\nbt\BigEndianNBTStream;
|
use pocketmine\nbt\BigEndianNBTStream;
|
||||||
@ -77,7 +76,7 @@ class JavaLevelData extends BaseNbtLevelData{
|
|||||||
protected function fix() : void{
|
protected function fix() : void{
|
||||||
if(!$this->compoundTag->hasTag("generatorName", StringTag::class)){
|
if(!$this->compoundTag->hasTag("generatorName", StringTag::class)){
|
||||||
$this->compoundTag->setString("generatorName", "default", true);
|
$this->compoundTag->setString("generatorName", "default", true);
|
||||||
}elseif(($generatorName = BaseLevelProvider::hackyFixForGeneratorClasspathInLevelDat($this->compoundTag->getString("generatorName"))) !== null){
|
}elseif(($generatorName = self::hackyFixForGeneratorClasspathInLevelDat($this->compoundTag->getString("generatorName"))) !== null){
|
||||||
$this->compoundTag->setString("generatorName", $generatorName);
|
$this->compoundTag->setString("generatorName", $generatorName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user