@@ -28,8 +28,6 @@ public class DownloadData {
2828 public int totalSize ;
2929 protected List <Download > downloadQueue = new ArrayList <>();
3030 protected AssetIndex assets ;
31- private Path serverZip ;
32- private Path serverJar ;
3331
3432 public DownloadData (MCP mcp , Version version ) {
3533 this (mcp , MCPPaths .get (mcp , MCPPaths .LIB ), MCPPaths .get (mcp , MCPPaths .JARS ), MCPPaths .get (mcp , MCPPaths .JAR_ORIGINAL , Side .CLIENT ), MCPPaths .get (mcp , MCPPaths .JAR_ORIGINAL , Side .SERVER ), version );
@@ -43,12 +41,12 @@ public DownloadData(MCP mcp, Path libraries, Path gameDir, Path client, Path ser
4341 Artifact serverArtifact = version .downloads .artifacts .get ("server" );
4442 if (mcp .getOptions ().getSide ().includesServer () && serverArtifact != null ) {
4543 Path serverOut = server ;
44+ Path serverExtractTo = null ;
4645 if (serverArtifact .url .endsWith (".zip" )) {
4746 serverOut = server .getParent ().resolve ("minecraft_server.zip" );
48- this .serverZip = serverOut ;
49- this .serverJar = server ;
47+ serverExtractTo = server ;
5048 }
51- queueDownload (serverArtifact , serverOut );
49+ queueDownload (serverArtifact , serverOut , serverExtractTo );
5250 }
5351 for (DependDownload dependencyDownload : version .libraries ) {
5452 if (Rule .apply (dependencyDownload .rules )) {
@@ -126,11 +124,15 @@ public void setAssets(AssetIndex assets) {
126124 }
127125
128126 public void queueDownload (IDownload dl , Path baseDir ) {
127+ queueDownload (dl , baseDir , null );
128+ }
129+
130+ private void queueDownload (IDownload dl , Path baseDir , Path extractTo ) {
129131 if (dl == null ) {
130132 return ;
131133 }
132134 totalSize += dl .downloadSize ();
133- downloadQueue .add (new Download (dl , baseDir ));
135+ downloadQueue .add (new Download (dl , baseDir , extractTo ));
134136 }
135137
136138 public void performDownload (DownloadListener listener ) throws IOException {
@@ -146,14 +148,13 @@ public void performDownload(DownloadListener listener) throws IOException {
146148 if (parent != null ) Files .createDirectories (parent );
147149 FileUtil .downloadFile (download .downloadURL (), file );
148150 }
151+ if (dl .extractTo != null ) {
152+ extractServerZip (file , dl .extractTo );
153+ }
149154 }
150- extractServerZip ();
151155 }
152156
153- private void extractServerZip () throws IOException {
154- if (serverZip == null || !Files .exists (serverZip )) {
155- return ;
156- }
157+ private void extractServerZip (Path serverZip , Path serverJar ) throws IOException {
157158 FileUtil .extractByExtension (serverZip , serverZip .getParent (), ".jar" );
158159 Path extracted = serverZip .getParent ().resolve ("minecraft-server.jar" );
159160 if (Files .exists (extracted )) {
@@ -164,10 +165,12 @@ private void extractServerZip() throws IOException {
164165 private static class Download {
165166 IDownload download ;
166167 Path dir ;
168+ Path extractTo ;
167169
168- public Download (IDownload dl , Path path ) {
170+ public Download (IDownload dl , Path path , Path extractTo ) {
169171 download = dl ;
170172 dir = path ;
173+ this .extractTo = extractTo ;
171174 }
172175 }
173176}
0 commit comments