mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
Make GameMode::fromString() and PluginEnableOrder::fromString() return null, instead of throwing exceptions
since these are always used for handling userdata, it doesn't make sense for them to throw exceptions.
This commit is contained in:
parent
3dd33cd35e
commit
6fb8ac211e
@ -51,9 +51,8 @@ class DefaultGamemodeCommand extends VanillaCommand{
|
||||
throw new InvalidCommandSyntaxException();
|
||||
}
|
||||
|
||||
try{
|
||||
$gameMode = GameMode::fromString($args[0]);
|
||||
}catch(\InvalidArgumentException $e){
|
||||
$gameMode = GameMode::fromString($args[0]);
|
||||
if($gameMode === null){
|
||||
$sender->sendMessage("Unknown game mode");
|
||||
return true;
|
||||
}
|
||||
|
@ -53,9 +53,8 @@ class GamemodeCommand extends VanillaCommand{
|
||||
throw new InvalidCommandSyntaxException();
|
||||
}
|
||||
|
||||
try{
|
||||
$gameMode = GameMode::fromString($args[0]);
|
||||
}catch(\InvalidArgumentException $e){
|
||||
$gameMode = GameMode::fromString($args[0]);
|
||||
if($gameMode === null){
|
||||
$sender->sendMessage("Unknown game mode");
|
||||
return true;
|
||||
}
|
||||
|
@ -61,13 +61,9 @@ final class GameMode{
|
||||
}
|
||||
}
|
||||
|
||||
public static function fromString(string $str) : self{
|
||||
public static function fromString(string $str) : ?self{
|
||||
self::checkInit();
|
||||
$result = self::$aliasMap[mb_strtolower($str)] ?? null;
|
||||
if($result === null){
|
||||
throw new \InvalidArgumentException("Invalid gamemode alias $str");
|
||||
}
|
||||
return $result;
|
||||
return self::$aliasMap[mb_strtolower($str)] ?? null;
|
||||
}
|
||||
|
||||
/** @var int */
|
||||
|
@ -151,11 +151,11 @@ class PluginDescription{
|
||||
$this->prefix = (string) ($plugin["prefix"] ?? $this->prefix);
|
||||
|
||||
if(isset($plugin["load"])){
|
||||
try{
|
||||
$this->order = PluginEnableOrder::fromString($plugin["load"]);
|
||||
}catch(\InvalidArgumentException $e){
|
||||
$order = PluginEnableOrder::fromString($plugin["load"]);
|
||||
if($order === null){
|
||||
throw new PluginException("Invalid Plugin \"load\"");
|
||||
}
|
||||
$this->order = $order;
|
||||
}else{
|
||||
$this->order = PluginEnableOrder::POSTWORLD();
|
||||
}
|
||||
|
@ -60,13 +60,9 @@ final class PluginEnableOrder{
|
||||
}
|
||||
}
|
||||
|
||||
public static function fromString(string $name) : self{
|
||||
public static function fromString(string $name) : ?self{
|
||||
self::checkInit();
|
||||
$result = self::$aliasMap[mb_strtolower($name)] ?? null;
|
||||
if($result === null){
|
||||
throw new \InvalidArgumentException("No such alias $name");
|
||||
}
|
||||
return $result;
|
||||
return self::$aliasMap[mb_strtolower($name)] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user