33namespace Boy132 \MinecraftModrinth \Services ;
44
55use App \Models \Server ;
6+ use Boy132 \MinecraftModrinth \Enums \MinecraftLoader ;
67use Boy132 \MinecraftModrinth \Enums \ModrinthProjectType ;
78use Exception ;
89use Illuminate \Support \Facades \Http ;
@@ -20,51 +21,10 @@ public function getMinecraftVersion(Server $server): ?string
2021 return $ version ;
2122 }
2223
23- public function getMinecraftLoader (Server $ server ): ?string
24- {
25- $ tags = $ server ->egg ->tags ?? [];
26-
27- if (in_array ('minecraft ' , $ tags )) {
28- if (in_array ('neoforge ' , $ tags ) || in_array ('neoforged ' , $ tags )) {
29- return 'neoforge ' ;
30- }
31-
32- if (in_array ('forge ' , $ tags )) {
33- return 'forge ' ;
34- }
35-
36- if (in_array ('fabric ' , $ tags )) {
37- return 'fabric ' ;
38- }
39-
40- if (in_array ('spigot ' , $ tags ) || in_array ('paper ' , $ tags )) {
41- return 'paper ' ;
42- }
43- }
44-
45- return null ;
46- }
47-
48- public function getModrinthProjectType (Server $ server ): ?ModrinthProjectType
49- {
50- $ features = $ server ->egg ->features ?? [];
51- $ tags = $ server ->egg ->tags ?? [];
52-
53- if (in_array ('modrinth_plugins ' , $ features ) || (in_array ('minecraft ' , $ tags ) && in_array ('plugins ' , $ features ))) {
54- return ModrinthProjectType::Plugin;
55- }
56-
57- if (in_array ('modrinth_mods ' , $ features ) || (in_array ('minecraft ' , $ tags ) && in_array ('mods ' , $ features ))) {
58- return ModrinthProjectType::Mod;
59- }
60-
61- return null ;
62- }
63-
6424 /** @return array{hits: array<int, array<string, mixed>>, total_hits: int} */
6525 public function getModrinthProjects (Server $ server , int $ page = 1 , ?string $ search = null ): array
6626 {
67- $ projectType = $ this -> getModrinthProjectType ($ server );
27+ $ projectType = ModrinthProjectType:: fromServer ($ server )?->value ;
6828
6929 if (!$ projectType ) {
7030 return [
@@ -74,15 +34,15 @@ public function getModrinthProjects(Server $server, int $page = 1, ?string $sear
7434 }
7535
7636 $ minecraftVersion = $ this ->getMinecraftVersion ($ server );
77- $ minecraftLoader = $ this -> getMinecraftLoader ($ server );
37+ $ minecraftLoader = MinecraftLoader:: fromServer ($ server )-> value ;
7838
7939 $ data = [
8040 'offset ' => ($ page - 1 ) * 20 ,
8141 'limit ' => 20 ,
82- 'facets ' => "[[ \"categories: $ minecraftLoader \"],[ \"versions: $ minecraftVersion \"],[ \"project_type: {$ projectType-> value }\"]] " ,
42+ 'facets ' => "[[ \"categories: $ minecraftLoader \"],[ \"versions: $ minecraftVersion \"],[ \"project_type: {$ projectType }\"]] " ,
8343 ];
8444
85- $ key = "modrinth_projects: {$ projectType-> value }: $ minecraftVersion: $ minecraftLoader: $ page " ;
45+ $ key = "modrinth_projects: {$ projectType }: $ minecraftVersion: $ minecraftLoader: $ page " ;
8646
8747 if ($ search ) {
8848 $ data ['query ' ] = $ search ;
@@ -113,7 +73,7 @@ public function getModrinthProjects(Server $server, int $page = 1, ?string $sear
11373 public function getModrinthVersions (string $ projectId , Server $ server ): array
11474 {
11575 $ minecraftVersion = $ this ->getMinecraftVersion ($ server );
116- $ minecraftLoader = $ this -> getMinecraftLoader ($ server );
76+ $ minecraftLoader = MinecraftLoader:: fromServer ($ server )-> value ;
11777
11878 $ data = [
11979 'game_versions ' => "[ \"$ minecraftVersion \"] " ,
0 commit comments