From 40fcfdf992990064ed16b57d5edf57efce5297a3 Mon Sep 17 00:00:00 2001 From: Henry Le Grys Date: Fri, 29 Jan 2021 16:21:59 +0000 Subject: [PATCH] Fix library handling bug in cases of bad JSON key ordering --- .../launcher/model/minecraft/Library.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/launcher/src/main/java/com/skcraft/launcher/model/minecraft/Library.java b/launcher/src/main/java/com/skcraft/launcher/model/minecraft/Library.java index 4959506..f6cd2d8 100644 --- a/launcher/src/main/java/com/skcraft/launcher/model/minecraft/Library.java +++ b/launcher/src/main/java/com/skcraft/launcher/model/minecraft/Library.java @@ -190,7 +190,9 @@ public class Library { Artifact virtualArtifact = new Artifact(); virtualArtifact.setUrl(url); - virtualArtifact.setPath(mavenNameToPath(name)); + if (getName() != null) { + virtualArtifact.setPath(mavenNameToPath(getName())); + } Downloads downloads = new Downloads(); downloads.setArtifact(virtualArtifact); @@ -198,13 +200,28 @@ public class Library { setDownloads(downloads); } + public void setName(String name) { + this.name = name; + + // [DEEP SIGH] + // Sometimes 'name' comes after 'url', and I can't figure out how to get Jackson to enforce order + // So we have to do this silly check to make sure we have a path. + if (getDownloads() != null) { + if (getDownloads().getArtifact() == null) return; + + if (getDownloads().getArtifact().getPath() == null) { + getDownloads().getArtifact().setPath(mavenNameToPath(name)); + } + } + } + /** * BACKWARDS COMPATIBILITY: * Some old Forge distributions use a parameter called "serverreq" to indicate that the dependency should * be fetched from the Minecraft library source; this setter handles that. */ public void setServerreq(boolean value) { - if (value) { + if (value && getDownloads() == null) { setUrl("https://libraries.minecraft.net/"); // TODO get this from properties? } }