46 lines
1.7 KiB
Java
46 lines
1.7 KiB
Java
package io.gitlab.jfronny.inceptum.util;
|
|
|
|
import io.gitlab.jfronny.inceptum.Inceptum;
|
|
import io.gitlab.jfronny.inceptum.model.mojang.AssetIndex;
|
|
import io.gitlab.jfronny.inceptum.model.mojang.VersionInfo;
|
|
import io.gitlab.jfronny.inceptum.model.mojang.VersionsList;
|
|
import io.gitlab.jfronny.inceptum.model.mojang.VersionsListInfo;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
|
|
import static io.gitlab.jfronny.inceptum.util.Utils.downloadObject;
|
|
|
|
public class McApi {
|
|
public static VersionsList getVersions() {
|
|
try {
|
|
return downloadObject("https://launchermeta.mojang.com/mc/game/version_manifest.json", VersionsList.class);
|
|
} catch (IOException e) {
|
|
throw new RuntimeException("Could not load version manifest", e);
|
|
}
|
|
}
|
|
|
|
public static VersionInfo getVersionInfo(VersionsListInfo listInfo) throws IOException {
|
|
return downloadObject(listInfo.url, VersionInfo.class);
|
|
}
|
|
|
|
public static AssetIndex getAssetIndex(VersionInfo info) throws IOException {
|
|
Path file = Inceptum.ASSETS_DIR.resolve("indexes");
|
|
if (!Files.exists(file)) Files.createDirectories(file);
|
|
file = file.resolve(Path.of(info.assetIndex.url).getFileName());
|
|
try {
|
|
Utils.downloadFile(info.assetIndex.url, info.assetIndex.sha1, file);
|
|
}
|
|
catch (IOException e) {
|
|
if (!Files.exists(file)) throw e;
|
|
}
|
|
return Utils.loadObject(file, AssetIndex.class);
|
|
}
|
|
|
|
public static void downloadAsset(AssetIndex.Asset asset, Path path) throws IOException {
|
|
String url = "http://resources.download.minecraft.net/" + asset.hash.substring(0, 2) + "/" + asset.hash;
|
|
Utils.downloadFile(url, asset.hash, path);
|
|
}
|
|
}
|