diff --git a/minecraft-modrinth/src/Enums/MinecraftLoader.php b/minecraft-modrinth/src/Enums/MinecraftLoader.php index 1a7db42e..984c83c6 100644 --- a/minecraft-modrinth/src/Enums/MinecraftLoader.php +++ b/minecraft-modrinth/src/Enums/MinecraftLoader.php @@ -4,6 +4,7 @@ use App\Models\Server; use Filament\Support\Contracts\HasLabel; +use Illuminate\Support\Str; enum MinecraftLoader: string implements HasLabel { @@ -12,56 +13,54 @@ enum MinecraftLoader: string implements HasLabel case Fabric = 'fabric'; case Quilt = 'quilt'; case Paper = 'paper'; + case Purpur = 'purpur'; + case Folia = 'folia'; + case Pufferfish = 'pufferfish'; + case Spigot = 'spigot'; + case Bukkit = 'bukkit'; case Velocity = 'velocity'; case Bungeecord = 'bungeecord'; + case Waterfall = 'waterfall'; public function getLabel(): string { - return str($this->name)->title(); + return Str::title($this->name); } - public static function fromServer(Server $server): ?MinecraftLoader + public static function fromServer(Server $server): ?self { $server->loadMissing('egg'); + /** @var string[] $tags */ $tags = $server->egg->tags ?? []; return self::fromTags($tags); } - /** @param string[] $tags */ - public static function fromTags(array $tags): ?MinecraftLoader + /** + * @param string[] $tags + */ + public static function fromTags(array $tags): ?self { - if (in_array('minecraft', $tags)) { - if (in_array('neoforge', $tags) || in_array('neoforged', $tags)) { - return self::NeoForge; - } - - if (in_array('forge', $tags)) { - return self::Forge; - } - - if (in_array('fabric', $tags)) { - return self::Fabric; - } - - if (in_array('quilt', $tags)) { - return self::Quilt; - } - - if (in_array('bukkit', $tags) || in_array('spigot', $tags) || in_array('paper', $tags)) { - return self::Paper; - } - - if (in_array('velocity', $tags)) { - return self::Velocity; - } - - if (in_array('waterfall', $tags) || in_array('bungeecord', $tags)) { - return self::Bungeecord; - } + if (!in_array('minecraft', $tags)) { + return null; } - return null; + return match (true) { + in_array('neoforge', $tags) || in_array('neoforged', $tags) => self::NeoForge, + in_array('forge', $tags) => self::Forge, + in_array('fabric', $tags) => self::Fabric, + in_array('quilt', $tags) => self::Quilt, + in_array('folia', $tags) => self::Folia, + in_array('purpur', $tags) => self::Purpur, + in_array('pufferfish', $tags) => self::Pufferfish, + in_array('paper', $tags) || in_array('papermc', $tags) => self::Paper, + in_array('spigot', $tags) || in_array('spigotmc', $tags) => self::Spigot, + in_array('bukkit', $tags) => self::Bukkit, + in_array('velocity', $tags) => self::Velocity, + in_array('waterfall', $tags) => self::Waterfall, + in_array('bungeecord', $tags) || in_array('bungee', $tags) => self::Bungeecord, + default => null, + }; } }