GeneratorManager: Make addGenerator() throw exceptions instead of returning false

This commit is contained in:
Dylan K. Taylor 2018-06-07 14:34:26 +01:00
parent 17b58357fb
commit 083a1e1ff6

View File

@ -44,17 +44,18 @@ final class GeneratorManager{
/**
* @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
*
* @return bool
* @param bool $overwrite Whether to force overwriting any existing registered generator with the same name
*/
public static function addGenerator(string $class, string $name) : bool{
if(is_subclass_of($class, Generator::class) and !isset(self::$list[$name = strtolower($name)])){
self::$list[$name] = $class;
return true;
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);
}
return false;
if(!$overwrite and isset(self::$list[$name = strtolower($name)])){
throw new \InvalidArgumentException("Alias \"$name\" is already assigned");
}
self::$list[$name] = $class;
}
/**