22declare(strict_types=1);
24namespace pocketmine\player;
28use
function mb_strtolower;
29use
function spl_object_id;
40 public static function fromString(
string $str) : ?self{
45 static $aliasMap = null;
47 if($aliasMap ===
null){
49 foreach(self::cases() as $case){
50 foreach($case->getAliases() as $alias){
51 $aliasMap[$alias] = $case;
56 return $aliasMap[mb_strtolower($str)] ??
null;
62 private function getMetadata() : array{
66 return $cache[spl_object_id($this)] ??= match($this){
67 self::SURVIVAL => [
"Survival", KnownTranslationFactory::gameMode_survival(), [
"survival",
"s",
"0"]],
68 self::CREATIVE => [
"Creative", KnownTranslationFactory::gameMode_creative(), [
"creative",
"c",
"1"]],
69 self::ADVENTURE => [
"Adventure", KnownTranslationFactory::gameMode_adventure(), [
"adventure",
"a",
"2"]],
70 self::SPECTATOR => [
"Spectator", KnownTranslationFactory::gameMode_spectator(), [
"spectator",
"v",
"view",
"3"]]
74 public function getEnglishName() : string{
75 return $this->getMetadata()[0];
78 public function getTranslatableName() : Translatable{
79 return $this->getMetadata()[1];
85 public function getAliases() : array{
86 return $this->getMetadata()[2];