fix cache dir creation for mojmap
All checks were successful
Publish to snapshot maven / build (push) Successful in 41s

This commit is contained in:
moehreag 2024-08-20 11:50:11 +02:00
parent f90baaef1b
commit 811b4e3611
2 changed files with 24 additions and 23 deletions

View file

@ -8,7 +8,7 @@ plugins {
} }
group = "dev.frogmc" group = "dev.frogmc"
version = "0.0.1-alpha.10" version = "0.0.1-alpha.11"
repositories { repositories {
mavenCentral() mavenCentral()

View file

@ -20,35 +20,36 @@ public class MojmapProvider {
return getMappings(gameVersion, cacheFile).map(ProguardParser::read).map(MappingBundle::new); return getMappings(gameVersion, cacheFile).map(ProguardParser::read).map(MappingBundle::new);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static Optional<String> getMappings(String gameVersion, Path cacheFile) { private static Optional<String> getMappings(String gameVersion, Path cacheFile) {
if (Files.exists(cacheFile)){ if (Files.exists(cacheFile)){
try { try {
return Optional.of(Files.readString(cacheFile, StandardCharsets.UTF_8)); return Optional.of(Files.readString(cacheFile, StandardCharsets.UTF_8));
} catch (IOException e) { } catch (IOException e) {
// TODO // TODO
e.printStackTrace(); e.printStackTrace();
} }
} }
return HttpHelper.getJson(Constants.VERSION_MANIFEST).flatMap(manifest -> { return HttpHelper.getJson(Constants.VERSION_MANIFEST).flatMap(manifest -> {
String versionName; String versionName;
if (gameVersion.startsWith("latest-")) { if (gameVersion.startsWith("latest-")) {
versionName = (String) ((Map<?, ?>) manifest.get("latest")).get(gameVersion.split("-")[1]); versionName = (String) ((Map<?, ?>) manifest.get("latest")).get(gameVersion.split("-")[1]);
} else { } else {
versionName = gameVersion; versionName = gameVersion;
} }
System.out.println("Loading version: " + versionName); System.out.println("Loading version: " + versionName);
for (UnmodifiableConfig version : (List<UnmodifiableConfig>) manifest.get("versions")) { for (UnmodifiableConfig version : (List<UnmodifiableConfig>) manifest.get("versions")) {
if (version.get("id").equals(versionName)) { if (version.get("id").equals(versionName)) {
UnmodifiableConfig versionManifest = HttpHelper.getJson(version.get("url")).orElseThrow(); UnmodifiableConfig versionManifest = HttpHelper.getJson(version.get("url")).orElseThrow();
String mappingsUrl = ((UnmodifiableConfig) ((UnmodifiableConfig) versionManifest String mappingsUrl = ((UnmodifiableConfig) ((UnmodifiableConfig) versionManifest
.get("downloads")).get("client_mappings")).get("url"); .get("downloads")).get("client_mappings")).get("url");
return HttpHelper.getString(mappingsUrl).map(s -> { return HttpHelper.getString(mappingsUrl).map(s -> {
try { try {
Files.createDirectories(cacheFile.getParent());
Files.writeString(cacheFile, s); Files.writeString(cacheFile, s);
} catch (IOException e) { } catch (IOException e) {
// TODO // TODO
@ -56,10 +57,10 @@ public class MojmapProvider {
} }
return s; return s;
}); });
} }
} }
return Optional.empty(); return Optional.empty();
}); });
} }
} }