Commits

Doc authored and md_5 committed d9217b2eba7
BUILDTOOLS-639: Replace static s3 url with Mojang API to download legacy vanilla server jars
No tags

src/main/java/org/spigotmc/builder/Builder.java

Modified
5 5 import com.google.common.collect.Iterables;
6 6 import com.google.common.collect.ObjectArrays;
7 7 import com.google.common.hash.HashFunction;
8 8 import com.google.common.hash.Hasher;
9 9 import com.google.common.hash.Hashing;
10 10 import com.google.common.io.ByteStreams;
11 11 import com.google.common.io.CharStreams;
12 12 import com.google.common.io.Files;
13 13 import com.google.common.io.Resources;
14 14 import com.google.gson.Gson;
15 +import com.google.gson.JsonArray;
16 +import com.google.gson.JsonElement;
17 +import com.google.gson.JsonObject;
15 18 import difflib.DiffUtils;
16 19 import difflib.Patch;
17 20 import java.awt.Desktop;
18 21 import java.io.BufferedOutputStream;
19 22 import java.io.BufferedReader;
20 23 import java.io.BufferedWriter;
21 24 import java.io.File;
22 25 import java.io.FileDescriptor;
23 26 import java.io.FileNotFoundException;
24 27 import java.io.FileOutputStream;
406 409
407 410 File vanillaJar = new File( workDir, "minecraft_server." + versionInfo.getMinecraftVersion() + ".jar" );
408 411 File embeddedVanillaJar = new File( workDir, "server-" + versionInfo.getMinecraftVersion() + ".jar" );
409 412 if ( !checkHash( vanillaJar, versionInfo ) )
410 413 {
411 414 if ( versionInfo.getServerUrl() != null )
412 415 {
413 416 download( versionInfo.getServerUrl(), vanillaJar, HashFormat.MD5, versionInfo.getMinecraftHash() );
414 417 } else
415 418 {
416 - download( String.format( "https://s3.amazonaws.com/Minecraft.Download/versions/%1$s/minecraft_server.%1$s.jar", versionInfo.getMinecraftVersion() ), vanillaJar, HashFormat.MD5, versionInfo.getMinecraftHash() );
419 + download( getServerVanillaUrl( versionInfo.getMinecraftVersion() ), vanillaJar, HashFormat.MD5, versionInfo.getMinecraftHash() );
417 420 }
418 421 }
419 422
420 423 try ( JarFile jar = new JarFile( vanillaJar ) )
421 424 {
422 425 ZipEntry entry = jar.getEntry( "META-INF/versions/" + versionInfo.getMinecraftVersion() + "/server-" + versionInfo.getMinecraftVersion() + ".jar" );
423 426 if ( entry != null )
424 427 {
425 428 if ( !checkHash( embeddedVanillaJar, HashFormat.SHA256, versionInfo.getMinecraftHash() ) )
426 429 {
1088 1091 if ( !dev && goodHash != null && !goodHash.equals( hash ) )
1089 1092 {
1090 1093 throw new IllegalStateException( "Downloaded file: " + target + " did not match expected hash: " + goodHash );
1091 1094 }
1092 1095
1093 1096 Files.write( bytes, target );
1094 1097
1095 1098 return target;
1096 1099 }
1097 1100
1101 + public static String getServerVanillaUrl(String version) throws Exception
1102 + {
1103 + Gson gson = new Gson();
1104 +
1105 + String responseManifest = get( "https://launchermeta.mojang.com/mc/game/version_manifest.json" );
1106 + JsonObject manifest = gson.fromJson( responseManifest, JsonObject.class );
1107 +
1108 + JsonArray manifestVersions = manifest.getAsJsonArray( "versions" );
1109 + for ( JsonElement manifestVersionElement : manifestVersions )
1110 + {
1111 + if ( manifestVersionElement.isJsonObject() )
1112 + {
1113 + JsonObject manifestVersion = manifestVersionElement.getAsJsonObject();
1114 + if ( manifestVersion.get( "id" ).getAsString().equals( version ) )
1115 + {
1116 + String urlVersionData = manifestVersion.get( "url" ).getAsString();
1117 +
1118 + String responseVersionData = get( urlVersionData );
1119 + JsonObject versionData = gson.fromJson( responseVersionData, JsonObject.class );
1120 + return versionData.getAsJsonObject( "downloads" ).getAsJsonObject( "server" ).get( "url" ).getAsString();
1121 + }
1122 + }
1123 + }
1124 +
1125 + throw new RuntimeException( "Error cannot get the URL for legacy server version " + version );
1126 + }
1127 +
1098 1128 public static void disableHttpsCertificateCheck()
1099 1129 {
1100 1130 // This globally disables certificate checking
1101 1131 // http://stackoverflow.com/questions/19723415/java-overriding-function-to-disable-ssl-certificate-check
1102 1132 try
1103 1133 {
1104 1134 TrustManager[] trustAllCerts = new TrustManager[]
1105 1135 {
1106 1136 new X509TrustManager()
1107 1137 {

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut