mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 08:39:53 +00:00
add boilerplate code to check for generator validity
perhaps we should use an enum for this...?
This commit is contained in:
parent
2cad7166b1
commit
2795ad674b
@ -25,6 +25,7 @@ namespace pocketmine\level\format\io\data;
|
|||||||
|
|
||||||
use pocketmine\level\format\io\exception\UnsupportedLevelFormatException;
|
use pocketmine\level\format\io\exception\UnsupportedLevelFormatException;
|
||||||
use pocketmine\level\generator\Flat;
|
use pocketmine\level\generator\Flat;
|
||||||
|
use pocketmine\level\generator\Generator;
|
||||||
use pocketmine\level\generator\GeneratorManager;
|
use pocketmine\level\generator\GeneratorManager;
|
||||||
use pocketmine\level\Level;
|
use pocketmine\level\Level;
|
||||||
use pocketmine\nbt\LittleEndianNbtSerializer;
|
use pocketmine\nbt\LittleEndianNbtSerializer;
|
||||||
@ -36,6 +37,7 @@ use pocketmine\nbt\tag\LongTag;
|
|||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
use pocketmine\network\mcpe\protocol\ProtocolInfo;
|
use pocketmine\network\mcpe\protocol\ProtocolInfo;
|
||||||
use pocketmine\utils\Binary;
|
use pocketmine\utils\Binary;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use function file_get_contents;
|
use function file_get_contents;
|
||||||
use function file_put_contents;
|
use function file_put_contents;
|
||||||
use function strlen;
|
use function strlen;
|
||||||
@ -51,6 +53,7 @@ class BedrockLevelData extends BaseNbtLevelData{
|
|||||||
public const GENERATOR_FLAT = 2;
|
public const GENERATOR_FLAT = 2;
|
||||||
|
|
||||||
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void{
|
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void{
|
||||||
|
Utils::testValidInstance($generator, Generator::class);
|
||||||
switch($generator){
|
switch($generator){
|
||||||
case Flat::class:
|
case Flat::class:
|
||||||
$generatorType = self::GENERATOR_FLAT;
|
$generatorType = self::GENERATOR_FLAT;
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\level\format\io\data;
|
namespace pocketmine\level\format\io\data;
|
||||||
|
|
||||||
|
use pocketmine\level\generator\Generator;
|
||||||
use pocketmine\level\generator\GeneratorManager;
|
use pocketmine\level\generator\GeneratorManager;
|
||||||
use pocketmine\level\Level;
|
use pocketmine\level\Level;
|
||||||
use pocketmine\nbt\BigEndianNbtSerializer;
|
use pocketmine\nbt\BigEndianNbtSerializer;
|
||||||
@ -32,6 +33,7 @@ use pocketmine\nbt\tag\FloatTag;
|
|||||||
use pocketmine\nbt\tag\IntTag;
|
use pocketmine\nbt\tag\IntTag;
|
||||||
use pocketmine\nbt\tag\LongTag;
|
use pocketmine\nbt\tag\LongTag;
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use function ceil;
|
use function ceil;
|
||||||
use function file_get_contents;
|
use function file_get_contents;
|
||||||
use function file_put_contents;
|
use function file_put_contents;
|
||||||
@ -40,6 +42,7 @@ use function microtime;
|
|||||||
class JavaLevelData extends BaseNbtLevelData{
|
class JavaLevelData extends BaseNbtLevelData{
|
||||||
|
|
||||||
public static function generate(string $path, string $name, int $seed, string $generator, array $options = [], int $version = 19133) : void{
|
public static function generate(string $path, string $name, int $seed, string $generator, array $options = [], int $version = 19133) : void{
|
||||||
|
Utils::testValidInstance($generator, Generator::class);
|
||||||
//TODO, add extra details
|
//TODO, add extra details
|
||||||
$levelData = new CompoundTag("Data", [
|
$levelData = new CompoundTag("Data", [
|
||||||
new ByteTag("hardcore", ($options["hardcore"] ?? false) === true ? 1 : 0),
|
new ByteTag("hardcore", ($options["hardcore"] ?? false) === true ? 1 : 0),
|
||||||
|
@ -32,12 +32,14 @@ use pocketmine\level\format\io\exception\UnsupportedChunkFormatException;
|
|||||||
use pocketmine\level\format\io\exception\UnsupportedLevelFormatException;
|
use pocketmine\level\format\io\exception\UnsupportedLevelFormatException;
|
||||||
use pocketmine\level\format\io\LevelData;
|
use pocketmine\level\format\io\LevelData;
|
||||||
use pocketmine\level\format\SubChunk;
|
use pocketmine\level\format\SubChunk;
|
||||||
|
use pocketmine\level\generator\Generator;
|
||||||
use pocketmine\nbt\LittleEndianNbtSerializer;
|
use pocketmine\nbt\LittleEndianNbtSerializer;
|
||||||
use pocketmine\nbt\NbtDataException;
|
use pocketmine\nbt\NbtDataException;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\utils\Binary;
|
use pocketmine\utils\Binary;
|
||||||
use pocketmine\utils\BinaryDataException;
|
use pocketmine\utils\BinaryDataException;
|
||||||
use pocketmine\utils\BinaryStream;
|
use pocketmine\utils\BinaryStream;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use function array_values;
|
use function array_values;
|
||||||
use function chr;
|
use function chr;
|
||||||
use function defined;
|
use function defined;
|
||||||
@ -119,6 +121,7 @@ class LevelDB extends BaseLevelProvider{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void{
|
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void{
|
||||||
|
Utils::testValidInstance($generator, Generator::class);
|
||||||
self::checkForLevelDBExtension();
|
self::checkForLevelDBExtension();
|
||||||
|
|
||||||
if(!file_exists($path . "/db")){
|
if(!file_exists($path . "/db")){
|
||||||
|
@ -28,7 +28,9 @@ use pocketmine\level\format\io\BaseLevelProvider;
|
|||||||
use pocketmine\level\format\io\data\JavaLevelData;
|
use pocketmine\level\format\io\data\JavaLevelData;
|
||||||
use pocketmine\level\format\io\exception\CorruptedChunkException;
|
use pocketmine\level\format\io\exception\CorruptedChunkException;
|
||||||
use pocketmine\level\format\io\LevelData;
|
use pocketmine\level\format\io\LevelData;
|
||||||
|
use pocketmine\level\generator\Generator;
|
||||||
use pocketmine\level\Level;
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use function assert;
|
use function assert;
|
||||||
use function file_exists;
|
use function file_exists;
|
||||||
use function is_dir;
|
use function is_dir;
|
||||||
@ -69,6 +71,7 @@ abstract class RegionLevelProvider extends BaseLevelProvider{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void{
|
public static function generate(string $path, string $name, int $seed, string $generator, array $options = []) : void{
|
||||||
|
Utils::testValidInstance($generator, Generator::class);
|
||||||
if(!file_exists($path)){
|
if(!file_exists($path)){
|
||||||
mkdir($path, 0777, true);
|
mkdir($path, 0777, true);
|
||||||
}
|
}
|
||||||
|
@ -94,6 +94,7 @@ final class GeneratorManager{
|
|||||||
* @throws \InvalidArgumentException if the class type cannot be matched to a known alias
|
* @throws \InvalidArgumentException if the class type cannot be matched to a known alias
|
||||||
*/
|
*/
|
||||||
public static function getGeneratorName(string $class) : string{
|
public static function getGeneratorName(string $class) : string{
|
||||||
|
Utils::testValidInstance($class, Generator::class);
|
||||||
foreach(self::$list as $name => $c){
|
foreach(self::$list as $name => $c){
|
||||||
if($c === $class){
|
if($c === $class){
|
||||||
return $name;
|
return $name;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user