mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-21 21:14:39 +00:00
GameMode::fromString() now throws InvalidArgumentException
This commit is contained in:
parent
e86ff7d988
commit
0b1bdec3ac
@ -40,6 +40,8 @@ final class GameMode{
|
||||
* @param string $str
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function fromString(string $str) : int{
|
||||
switch(strtolower(trim($str))){
|
||||
@ -65,7 +67,7 @@ final class GameMode{
|
||||
return self::SPECTATOR;
|
||||
}
|
||||
|
||||
return -1;
|
||||
throw new \InvalidArgumentException("Unknown gamemode string \"$str\"");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,15 +49,16 @@ class DefaultGamemodeCommand extends VanillaCommand{
|
||||
throw new InvalidCommandSyntaxException();
|
||||
}
|
||||
|
||||
$gameMode = GameMode::fromString($args[0]);
|
||||
|
||||
if($gameMode !== -1){
|
||||
$sender->getServer()->setConfigInt("gamemode", $gameMode);
|
||||
$sender->sendMessage(new TranslationContainer("commands.defaultgamemode.success", [GameMode::toTranslation($gameMode)]));
|
||||
}else{
|
||||
try{
|
||||
$gameMode = GameMode::fromString($args[0]);
|
||||
}catch(\InvalidArgumentException $e){
|
||||
$sender->sendMessage("Unknown game mode");
|
||||
return true;
|
||||
}
|
||||
|
||||
$sender->getServer()->setConfigInt("gamemode", $gameMode);
|
||||
$sender->sendMessage(new TranslationContainer("commands.defaultgamemode.success", [GameMode::toTranslation($gameMode)]));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -52,11 +52,10 @@ class GamemodeCommand extends VanillaCommand{
|
||||
throw new InvalidCommandSyntaxException();
|
||||
}
|
||||
|
||||
$gameMode = GameMode::fromString($args[0]);
|
||||
|
||||
if($gameMode === -1){
|
||||
try{
|
||||
$gameMode = GameMode::fromString($args[0]);
|
||||
}catch(\InvalidArgumentException $e){
|
||||
$sender->sendMessage("Unknown game mode");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user