mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
First look at loading 1.13+ worlds
This commit is contained in:
@ -180,13 +180,13 @@ final class BlockStateUpgradeSchemaUtils{
|
||||
*
|
||||
* @return BlockStateUpgradeSchema[]
|
||||
*/
|
||||
public static function loadSchemas(string $path) : array{
|
||||
public static function loadSchemas(string $path, int $currentVersion) : array{
|
||||
$iterator = new \RegexIterator(
|
||||
new \FilesystemIterator(
|
||||
$path,
|
||||
\FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS
|
||||
),
|
||||
'/\/mapping_schema_(\d{4}).*\.json$/',
|
||||
'/\/(\d{4}).*\.json$/',
|
||||
\RegexIterator::GET_MATCH
|
||||
);
|
||||
|
||||
@ -209,7 +209,14 @@ final class BlockStateUpgradeSchemaUtils{
|
||||
}
|
||||
$model = $jsonMapper->map($json, new BlockStateUpgradeSchemaModel());
|
||||
|
||||
$result[$priority] = self::fromJsonModel($model);
|
||||
$schema = self::fromJsonModel($model);
|
||||
if($schema->getVersionId() > $currentVersion){
|
||||
//this might be a beta schema which shouldn't be applicable
|
||||
//TODO: why do we load the whole schema just to throw it away if it's too new? ...
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[$priority] = $schema;
|
||||
}
|
||||
|
||||
ksort($result, SORT_NUMERIC);
|
||||
|
@ -34,6 +34,16 @@ final class BlockStateUpgrader{
|
||||
/** @var BlockStateUpgradeSchema[][] */
|
||||
private array $upgradeSchemas = [];
|
||||
|
||||
/**
|
||||
* @param BlockStateUpgradeSchema[] $upgradeSchemas
|
||||
* @phpstan-param array<int, BlockStateUpgradeSchema> $upgradeSchemas
|
||||
*/
|
||||
public function __construct(array $upgradeSchemas){
|
||||
foreach($upgradeSchemas as $priority => $schema){
|
||||
$this->addSchema($schema, $priority);
|
||||
}
|
||||
}
|
||||
|
||||
public function addSchema(BlockStateUpgradeSchema $schema, int $priority) : void{
|
||||
if(isset($this->upgradeSchemas[$schema->getVersionId()][$priority])){
|
||||
throw new \InvalidArgumentException("Another schema already has this priority");
|
||||
|
Reference in New Issue
Block a user