@@ -54,13 +54,13 @@ public static void downloadDefaultLibraries(Path basePath, Callback<File> callba
5454 LibraryProcessor .downloadLibrary ("default libraries" , basePath , defaults .getLibs (), callback );
5555 }
5656
57- public static void setupMinecraft (Path basePath , String version , Callback <File > callback ) {
57+ public static void setupMinecraft (Constants . Side side , Path basePath , String version , Callback <File > callback ) {
5858 if (version == null ) {
5959 Logger .fatal ("Can not find minecraft version" );
6060 System .exit (0 );
6161 }
6262 // Set correct paths
63- Constants .setMinecraftPaths (basePath , version );
63+ Constants .setMinecraftPaths (side , basePath , version );
6464 // Make sure we have the correct directories
6565 if (!Constants .MINECRAFT_PATH .toFile ().exists () && !Constants .MINECRAFT_PATH .toFile ().mkdirs ()) {
6666 Logger .fatal ("Failed to make minecraft directory" );
@@ -71,7 +71,7 @@ public static void setupMinecraft(Path basePath, String version, Callback<File>
7171 try (InputStreamReader manifestReader = new InputStreamReader (new URL (Constants .VERSION_MANIFEST_ENDPOINT ).openStream ())) {
7272 MinecraftVersionManifest manifest = new Gson ().fromJson (manifestReader , MinecraftVersionManifest .class );
7373 Optional <MinecraftVersionManifestType > versionInfo = getVersion (manifest , Constants .MINECRAFT_VERSION );
74- // Read version json and get server info
74+ // Read version json and get info
7575 if (versionInfo .isPresent () && versionInfo .get ().getUrl () != null && !versionInfo .get ().getUrl ().isEmpty ()) {
7676 try {
7777 Logger .info ("Downloading version json" );
@@ -105,7 +105,7 @@ public static void setupMinecraft(Path basePath, String version, Callback<File>
105105 // Download libraries
106106 List <JsonLibraryInfo > minecraftLibraries = new ArrayList <>();
107107 for (MinecraftLibrary minecraftLibrary : minecraftVersion .getLibraries ()) {
108- // Should not need mac only for a server . I think?
108+ // Should not need mac only. I think?
109109 if (!minecraftLibrary .isMac ()) {
110110 String [] minecraftLib = minecraftLibrary .getName ().split (":" );
111111 minecraftLibraries .add (new JsonLibraryInfo ("maven" , minecraftLib [0 ], minecraftLib [1 ], minecraftLib [2 ], Constants .MINECRAFT_REPO ));
@@ -114,47 +114,49 @@ public static void setupMinecraft(Path basePath, String version, Callback<File>
114114 // Download all the Minecraft libraries
115115 LibraryProcessor .downloadLibrary ("Minecraft libraries" , basePath , minecraftLibraries , callback );
116116 // Download Minecraft and patch if we don't have the file
117- if (!Constants .SERVER_MAPPED_JAR_PATH .toFile ().exists ()) {
118- // Download server
119- if (!minecraftVersion .getDownloads ().getServer ().getUrl ().isEmpty ()) {
117+ if (!Constants .MAPPED_JAR_PATH .toFile ().exists ()) {
118+ // Download jar
119+ String jarDownload = side == Constants .Side .SERVER ? minecraftVersion .getDownloads ().getServer ().getUrl () : minecraftVersion .getDownloads ().getClient ().getUrl ();
120+ if (!jarDownload .isEmpty ()) {
120121 try {
121- Logger .info ("Downloading Minecraft server (" + Constants .MINECRAFT_VERSION + ")" );
122- downloadFile (new URL (minecraftVersion . getDownloads (). getServer (). getUrl ()) , Constants .SERVER_JAR_PATH .toFile ());
122+ Logger .info ("Downloading Minecraft " + side . name (). toLowerCase () + " (" + Constants .MINECRAFT_VERSION + ")" );
123+ downloadFile (new URL (jarDownload ) , Constants .JAR_PATH .toFile ());
123124 } catch (IOException e ) {
124- Logger .exception ("Error creating server url" , e );
125+ Logger .exception ("Error creating " + side . name (). toLowerCase () + " url" , e );
125126 System .exit (0 );
126127 }
127128 } else {
128- Logger .fatal ("Error reading Minecraft server url" );
129+ Logger .fatal ("Error reading Minecraft " + side . name (). toLowerCase () + " url" );
129130 System .exit (0 );
130131 }
131132 // Cleanup Minecraft
132133 Logger .info ("Cleaning up Minecraft" );
133- deleteMinecraftTrash (Constants .SERVER_JAR_PATH .toFile ());
134+ // deleteMinecraftTrash(Constants.JAR_PATH .toFile());
134135 Logger .info ("Cleaned up Minecraft" );
135- // Download server mappings
136- if (!minecraftVersion .getDownloads ().getServerMappings ().getUrl ().isEmpty ()) {
136+ // Download mappings
137+ String mappingsDownload = side == Constants .Side .SERVER ? minecraftVersion .getDownloads ().getServerMappings ().getUrl () : minecraftVersion .getDownloads ().getClientMappings ().getUrl ();
138+ if (!mappingsDownload .isEmpty ()) {
137139 try {
138- Logger .info ("Downloading server mappings" );
139- downloadFile (new URL (minecraftVersion . getDownloads (). getServerMappings (). getUrl ()) , Constants .SERVER_MAPPINGS_PATH .toFile ());
140+ Logger .info ("Downloading " + side . name (). toLowerCase () + " mappings" );
141+ downloadFile (new URL (mappingsDownload ) , Constants .MAPPINGS_PATH .toFile ());
140142 } catch (IOException e ) {
141- Logger .exception ("Error creating server mappings url" , e );
143+ Logger .exception ("Error creating " + side . name (). toLowerCase () + " mappings url" , e );
142144 System .exit (0 );
143145 }
144146 } else {
145- Logger .fatal ("Error reading Minecraft server mappings url" );
147+ Logger .fatal ("Error reading Minecraft " + side . name (). toLowerCase () + " mappings url" );
146148 System .exit (0 );
147149 }
148150 // Convert Minecraft mappings
149151 Logger .info ("Converting Minecraft mappings" );
150- new Mojang2Tsrg (Constants .SERVER_MAPPINGS_PATH , Constants .SERVER_MAPPINGS_CONVERTED_PATH );
152+ new Mojang2Tsrg (Constants .MAPPINGS_PATH , Constants .MAPPINGS_CONVERTED_PATH );
151153 // Remapping Minecraft
152- Logger .info ("Remapping Minecraft (This might take a bit)" );
154+ Logger .info ("Remapping Minecraft " + side . name (). toLowerCase () + " (This might take a bit)" );
153155 ClassLoader classLoader = new URLClassLoader (specialSourcePaths .toArray (new URL []{}), ClassLoader .getSystemClassLoader ());
154156 String [] specialSourceArgs = Stream .of (
155- "--in-jar" , Constants .SERVER_JAR_PATH .toFile ().getAbsolutePath (),
156- "--out-jar" , Constants .SERVER_MAPPED_JAR_PATH .toFile ().getAbsolutePath (),
157- "--srg-in" , Constants .SERVER_MAPPINGS_CONVERTED_PATH .toFile ().getAbsolutePath (),
157+ "--in-jar" , Constants .JAR_PATH .toFile ().getAbsolutePath (),
158+ "--out-jar" , Constants .MAPPED_JAR_PATH .toFile ().getAbsolutePath (),
159+ "--srg-in" , Constants .MAPPINGS_CONVERTED_PATH .toFile ().getAbsolutePath (),
158160 "--quiet"
159161 ).toArray (String []::new );
160162 // Run remapping Minecraft
@@ -164,10 +166,11 @@ public static void setupMinecraft(Path basePath, String version, Callback<File>
164166 method .invoke (null , (Object ) specialSourceArgs );
165167 } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e ) {
166168 Logger .exception ("Error remapping Minecraft" , e );
169+ e .printStackTrace ();
167170 System .exit (0 );
168171 }
169- Constants .SERVER_JAR_PATH .toFile ().delete ();
170- Constants .SERVER_MAPPINGS_CONVERTED_PATH .toFile ().delete ();
172+ Constants .JAR_PATH .toFile ().delete ();
173+ Constants .MAPPINGS_CONVERTED_PATH .toFile ().delete ();
171174 Logger .info ("Remapped Minecraft" );
172175 }
173176 }
0 commit comments