package io.gitlab.jfronny.resclone.fetchers; import io.gitlab.jfronny.resclone.Resclone; import io.gitlab.jfronny.resclone.data.CfAddon; import io.gitlab.jfronny.resclone.util.UrlUtils; import net.minecraft.MinecraftVersion; import java.text.SimpleDateFormat; import java.util.Date; public class CurseforgeFetcher extends BasePackFetcher { @Override public String getSourceTypeName() { return "curseforge"; } @Override public String getDownloadUrl(String baseUrl) throws Exception { try { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS'Z'"); String version = MinecraftVersion.CURRENT.getName(); CfAddon latest = null; Date latestDate = null; boolean foundMatchingVersion = false; for (CfAddon addon : UrlUtils.readJsonFromURLSet("https://addons-ecs.forgesvc.net/api/v2/addon/" + baseUrl + "/files", CfAddon.class)) { Date d = df.parse(addon.fileDate); if (foundMatchingVersion && !addon.gameVersion.contains(version)) continue; if (!foundMatchingVersion && addon.gameVersion.contains(version)) { foundMatchingVersion = true; latest = null; } if (latest == null || d.after(latestDate)) { latest = addon; latestDate = d; } } if (!foundMatchingVersion) Resclone.LOGGER.error("Could not find pack for matching version, using latest"); return latest.downloadUrl; } catch (Throwable e) { throw new Exception("Could not get CF download for " + baseUrl, e); } } }