mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-15 06:09:49 +00:00
WorldProviders now have the following requirements removed: - __construct() is no longer required to have a specific signature - static isValid() no longer needs to be implemented (you will still need it for registering, but it can be declared anywhere now) - static generate() no longer needs to be implemented This paves the way for more interesting types of world providers that use something other than local disk to store chunks (e.g. a mysql database). WorldProviderManager no longer accepts class-string<WorldProvider>. Instead, WorldProviderManagerEntry is required, with 2 or 3 callbacks: - ReadOnlyWorldProviderManager must provide a callback for isValid, and a callback for fromPath - WritableWorldProviderManagerEntry must provide the same, and also a generate() callback In practice, this requires zero changes to the WorldProviders themselves, since a WorldProviderManagerEntry can be created like this: `new WritableWorldProviderManagerEntry(\Closure::fromCallable([LevelDB::class, 'isValid']), fn(string ) => new LevelDB(), \Closure::fromCallable([LevelDB::class, 'generate']))` This provides identical functionality to before for the provider itself; only registration is changed.
54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\world\format\io;
|
|
|
|
use pocketmine\world\format\io\exception\CorruptedWorldException;
|
|
use pocketmine\world\format\io\exception\UnsupportedWorldFormatException;
|
|
|
|
/**
|
|
* @phpstan-type IsValid \Closure(string $path) : bool
|
|
*/
|
|
abstract class WorldProviderManagerEntry{
|
|
|
|
/** @phpstan-var IsValid */
|
|
protected \Closure $isValid;
|
|
|
|
/** @phpstan-param IsValid $isValid */
|
|
protected function __construct(\Closure $isValid){
|
|
$this->isValid = $isValid;
|
|
}
|
|
|
|
/**
|
|
* Tells if the path is a valid world.
|
|
* This must tell if the current format supports opening the files in the directory
|
|
*/
|
|
public function isValid(string $path) : bool{ return ($this->isValid)($path); }
|
|
|
|
/**
|
|
* @throws CorruptedWorldException
|
|
* @throws UnsupportedWorldFormatException
|
|
*/
|
|
abstract public function fromPath(string $path) : WorldProvider;
|
|
}
|