mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-09 11:31:49 +00:00
GeneratorManager: allow aliasing existing generators
This commit is contained in:
parent
37f2dafae1
commit
e48b5b2ec0
@ -52,9 +52,9 @@ final class GeneratorManager{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
$this->addGenerator(Normal::class, "normal", fn() => null);
|
$this->addGenerator(Normal::class, "normal", fn() => null);
|
||||||
$this->addGenerator(Normal::class, "default", fn() => null);
|
$this->addAlias("normal", "default");
|
||||||
$this->addGenerator(Nether::class, "hell", fn() => null);
|
|
||||||
$this->addGenerator(Nether::class, "nether", fn() => null);
|
$this->addGenerator(Nether::class, "nether", fn() => null);
|
||||||
|
$this->addAlias("nether", "hell");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,6 +80,22 @@ final class GeneratorManager{
|
|||||||
$this->list[$name] = new GeneratorManagerEntry($class, $presetValidator);
|
$this->list[$name] = new GeneratorManagerEntry($class, $presetValidator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aliases an already-registered generator name to another name. Useful if you want to map a generator name to an
|
||||||
|
* existing generator without having to replicate the parameters.
|
||||||
|
*/
|
||||||
|
public function addAlias(string $name, string $alias) : void{
|
||||||
|
$name = strtolower($name);
|
||||||
|
$alias = strtolower($alias);
|
||||||
|
if(!isset($this->list[$name])){
|
||||||
|
throw new \InvalidArgumentException("Alias \"$name\" is not assigned");
|
||||||
|
}
|
||||||
|
if(isset($this->list[$alias])){
|
||||||
|
throw new \InvalidArgumentException("Alias \"$alias\" is already assigned");
|
||||||
|
}
|
||||||
|
$this->list[$alias] = $this->list[$name];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of names for registered generators.
|
* Returns a list of names for registered generators.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user