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 $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 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
* @return bool
*/ */
public static function addGenerator(string $class, string $name) : bool{ public static function addGenerator(string $class, string $name, bool $overwrite = false) : void{
if(is_subclass_of($class, Generator::class) and !isset(self::$list[$name = strtolower($name)])){ if(!is_subclass_of($class, Generator::class)){
self::$list[$name] = $class; throw new \InvalidArgumentException("Class $class does not extend " . Generator::class);
return true;
} }
return false; if(!$overwrite and isset(self::$list[$name = strtolower($name)])){
throw new \InvalidArgumentException("Alias \"$name\" is already assigned");
}
self::$list[$name] = $class;
} }
/** /**