package io.gitlab.jfronny.glaunch.util.mojang; import io.gitlab.jfronny.glaunch.GLaunch; import io.gitlab.jfronny.glaunch.model.AssetIndex; import io.gitlab.jfronny.glaunch.model.VersionInfo; import io.gitlab.jfronny.glaunch.model.VersionsList; import io.gitlab.jfronny.glaunch.model.VersionsListInfo; import io.gitlab.jfronny.glaunch.util.Utils; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import static io.gitlab.jfronny.glaunch.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 = GLaunch.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); } }