classname mapping */ private static $list = []; /** * Registers the default known generators. */ public static function registerDefaultGenerators() : void{ self::addGenerator(Flat::class, "flat"); self::addGenerator(Normal::class, "normal"); self::addGenerator(Normal::class, "default"); self::addGenerator(Nether::class, "hell"); self::addGenerator(Nether::class, "nether"); } /** * @param string $class Fully qualified name of class that extends \pocketmine\level\generator\Generator * @param string $name Alias for this generator type that can be written in configs * @param bool $overwrite Whether to force overwriting any existing registered generator with the same name */ public static function addGenerator(string $class, string $name, bool $overwrite = false) : void{ if(!is_subclass_of($class, Generator::class)){ throw new \InvalidArgumentException("Class $class does not extend " . Generator::class); } if(!$overwrite and isset(self::$list[$name = strtolower($name)])){ throw new \InvalidArgumentException("Alias \"$name\" is already assigned"); } self::$list[$name] = $class; } /** * Returns a list of names for registered generators. * * @return string[] */ public static function getGeneratorList() : array{ return array_keys(self::$list); } /** * Returns a class name of a registered Generator matching the given name. * * @param string $name * @param bool $throwOnMissing @deprecated this is for backwards compatibility only * * @return string|Generator Name of class that extends Generator (not an actual Generator object) * @throws \InvalidArgumentException if the generator type isn't registered */ public static function getGenerator(string $name, bool $throwOnMissing = false){ if(isset(self::$list[$name = strtolower($name)])){ return self::$list[$name]; } if($throwOnMissing){ throw new \InvalidArgumentException("Alias \"$name\" does not map to any known generator"); } return Normal::class; } /** * Returns the registered name of the given Generator class. * * @param string $class Fully qualified name of class that extends \pocketmine\level\generator\Generator * * @return string */ public static function getGeneratorName(string $class) : string{ foreach(self::$list as $name => $c){ if($c === $class){ return $name; } } return "unknown"; } private function __construct(){ //NOOP } }