22declare(strict_types=1);
24namespace pocketmine\player;
28use pocketmine\utils\LegacyEnumShimTrait;
29use
function mb_strtolower;
30use
function spl_object_id;
44 use LegacyEnumShimTrait;
51 public static function fromString(
string $str) : ?self{
56 static $aliasMap = null;
58 if($aliasMap ===
null){
60 foreach(self::cases() as $case){
61 foreach($case->getAliases() as $alias){
62 $aliasMap[$alias] = $case;
67 return $aliasMap[mb_strtolower($str)] ??
null;
73 private function getMetadata() : array{
77 return $cache[spl_object_id($this)] ??= match($this){
78 self::SURVIVAL => [
"Survival", KnownTranslationFactory::gameMode_survival(), [
"survival",
"s",
"0"]],
79 self::CREATIVE => [
"Creative", KnownTranslationFactory::gameMode_creative(), [
"creative",
"c",
"1"]],
80 self::ADVENTURE => [
"Adventure", KnownTranslationFactory::gameMode_adventure(), [
"adventure",
"a",
"2"]],
81 self::SPECTATOR => [
"Spectator", KnownTranslationFactory::gameMode_spectator(), [
"spectator",
"v",
"view",
"3"]]
85 public function getEnglishName() : string{
86 return $this->getMetadata()[0];
89 public function getTranslatableName() : Translatable{
90 return $this->getMetadata()[1];
96 public function getAliases() : array{
97 return $this->getMetadata()[2];