mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Fixed issues with LevelDB worlds silently getting overwritten with the default format when LevelDB extension is not loaded
Always register the level provider (to allow detecting the world format) but throw exceptions if anything tries to use it without the extension being loaded.
This commit is contained in:
parent
3bc3a0bb49
commit
7e496afdd1
@ -1657,12 +1657,11 @@ class Server{
|
||||
LevelProviderManager::addProvider(Anvil::class);
|
||||
LevelProviderManager::addProvider(McRegion::class);
|
||||
LevelProviderManager::addProvider(PMAnvil::class);
|
||||
LevelProviderManager::addProvider(LevelDB::class);
|
||||
if(extension_loaded("leveldb")){
|
||||
$this->logger->debug($this->getLanguage()->translateString("pocketmine.debug.enable"));
|
||||
LevelProviderManager::addProvider(LevelDB::class);
|
||||
}
|
||||
|
||||
|
||||
Generator::addGenerator(Flat::class, "flat");
|
||||
Generator::addGenerator(Normal::class, "normal");
|
||||
Generator::addGenerator(Normal::class, "default");
|
||||
|
@ -77,7 +77,15 @@ class LevelDB extends BaseLevelProvider{
|
||||
/** @var \LevelDB */
|
||||
protected $db;
|
||||
|
||||
private static function checkForLevelDBExtension(){
|
||||
if(!extension_loaded('leveldb')){
|
||||
throw new LevelException("The leveldb PHP extension is required to use this world format");
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct(Level $level, string $path){
|
||||
self::checkForLevelDBExtension();
|
||||
|
||||
$this->level = $level;
|
||||
$this->path = $path;
|
||||
if(!file_exists($this->path)){
|
||||
@ -92,6 +100,7 @@ class LevelDB extends BaseLevelProvider{
|
||||
throw new LevelException("Invalid level.dat");
|
||||
}
|
||||
|
||||
|
||||
$this->db = new \LevelDB($this->path . "/db", [
|
||||
"compression" => LEVELDB_ZLIB_COMPRESSION
|
||||
]);
|
||||
@ -145,6 +154,8 @@ class LevelDB extends BaseLevelProvider{
|
||||
}
|
||||
|
||||
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []){
|
||||
self::checkForLevelDBExtension();
|
||||
|
||||
if(!file_exists($path)){
|
||||
mkdir($path, 0777, true);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user