mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-19 04:15:04 +00:00
Move gamemode constants & functions to their own class
future enhancements: - make gamemode an object containing information about abilities that players have in this gamemode (gamemodes are just predefined ability sets) - get the magic numbers out of the API
This commit is contained in:
@@ -526,76 +526,6 @@ class Server{
|
||||
return $this->getConfigBool("force-gamemode", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the gamemode text name
|
||||
*
|
||||
* @param int $mode
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getGamemodeString(int $mode) : string{
|
||||
switch($mode){
|
||||
case Player::SURVIVAL:
|
||||
return "%gameMode.survival";
|
||||
case Player::CREATIVE:
|
||||
return "%gameMode.creative";
|
||||
case Player::ADVENTURE:
|
||||
return "%gameMode.adventure";
|
||||
case Player::SPECTATOR:
|
||||
return "%gameMode.spectator";
|
||||
}
|
||||
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
public static function getGamemodeName(int $mode) : string{
|
||||
switch($mode){
|
||||
case Player::SURVIVAL:
|
||||
return "Survival";
|
||||
case Player::CREATIVE:
|
||||
return "Creative";
|
||||
case Player::ADVENTURE:
|
||||
return "Adventure";
|
||||
case Player::SPECTATOR:
|
||||
return "Spectator";
|
||||
default:
|
||||
throw new \InvalidArgumentException("Invalid gamemode $mode");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a string and returns a gamemode integer, -1 if not found
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getGamemodeFromString(string $str) : int{
|
||||
switch(strtolower(trim($str))){
|
||||
case (string) Player::SURVIVAL:
|
||||
case "survival":
|
||||
case "s":
|
||||
return Player::SURVIVAL;
|
||||
|
||||
case (string) Player::CREATIVE:
|
||||
case "creative":
|
||||
case "c":
|
||||
return Player::CREATIVE;
|
||||
|
||||
case (string) Player::ADVENTURE:
|
||||
case "adventure":
|
||||
case "a":
|
||||
return Player::ADVENTURE;
|
||||
|
||||
case (string) Player::SPECTATOR:
|
||||
case "spectator":
|
||||
case "view":
|
||||
case "v":
|
||||
return Player::SPECTATOR;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Server global difficulty. Note that this may be overridden in individual Levels.
|
||||
* @return int
|
||||
@@ -2237,7 +2167,7 @@ class Server{
|
||||
$this->dispatchSignals = true;
|
||||
}
|
||||
|
||||
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.defaultGameMode", [self::getGamemodeString($this->getGamemode())]));
|
||||
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.defaultGameMode", [Gamemode::toTranslation($this->getGamemode())]));
|
||||
|
||||
$this->logger->info($this->getLanguage()->translateString("pocketmine.server.startFinished", [round(microtime(true) - \pocketmine\START_TIME, 3)]));
|
||||
|
||||
|
Reference in New Issue
Block a user