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