22declare(strict_types=1);
26use pocketmine\utils\SingletonTrait;
30use
function array_keys;
31use
function strtolower;
40 private array $list = [];
42 public function __construct(){
54 $this->
addGenerator(Normal::class,
"normal", fn() =>
null);
55 $this->
addAlias(
"normal",
"default");
56 $this->
addGenerator(Nether::class,
"nether", fn() =>
null);
72 public function addGenerator(
string $class,
string $name, \Closure $presetValidator,
bool $overwrite =
false) : void{
75 $name = strtolower($name);
76 if(!$overwrite && isset($this->list[$name])){
77 throw new \InvalidArgumentException(
"Alias \"$name\" is already assigned");
87 public function addAlias(
string $name,
string $alias) : void{
88 $name = strtolower($name);
89 $alias = strtolower($alias);
90 if(!isset($this->list[$name])){
91 throw new \InvalidArgumentException(
"Alias \"$name\" is not assigned");
93 if(isset($this->list[$alias])){
94 throw new \InvalidArgumentException(
"Alias \"$alias\" is already assigned");
96 $this->list[$alias] = $this->list[$name];
105 return array_keys($this->list);
112 return $this->list[strtolower($name)] ?? null;
125 foreach(Utils::stringifyKeys($this->list) as $name => $c){
126 if($c->getGeneratorClass() === $class){
131 throw new \InvalidArgumentException(
"Generator class $class is not registered");
static parsePreset(string $presetString)
addGenerator(string $class, string $name, \Closure $presetValidator, bool $overwrite=false)
getGenerator(string $name)
addAlias(string $name, string $alias)
getGeneratorName(string $class)