diff --git a/HMCL/src/core/java/org/jackhuang/hellominecraft/launcher/core/mod/ModInfo.java b/HMCL/src/core/java/org/jackhuang/hellominecraft/launcher/core/mod/ModInfo.java index f508b2acc..5de1ab074 100755 --- a/HMCL/src/core/java/org/jackhuang/hellominecraft/launcher/core/mod/ModInfo.java +++ b/HMCL/src/core/java/org/jackhuang/hellominecraft/launcher/core/mod/ModInfo.java @@ -17,13 +17,15 @@ */ package org.jackhuang.hellominecraft.launcher.core.mod; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; import com.google.gson.annotations.SerializedName; import com.google.gson.reflect.TypeToken; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; -import java.lang.reflect.Type; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -60,6 +62,8 @@ public class ModInfo implements Comparable { public String credits; @SerializedName("authorList") public String[] authorList; + @SerializedName("authors") + public String[] authors; public boolean isActive() { return !location.getName().endsWith(".disabled"); @@ -87,6 +91,8 @@ public class ModInfo implements Comparable { public String getAuthor() { if (authorList != null && authorList.length > 0) return StrUtils.parseParams("", authorList, ", "); + else if (authors != null && authors.length > 0) + return StrUtils.parseParams("", authors, ", "); else if (StrUtils.isNotBlank(author)) return author; else @@ -123,18 +129,30 @@ public class ModInfo implements Comparable { return name.endsWith(".zip") || name.endsWith(".jar") || name.endsWith("litemod"); } - private static final Type TYPE = new TypeToken>() { - }.getType(); - private static ModInfo getForgeModInfo(File f, ZipFile jar, ZipEntry entry) throws IOException { - ModInfo i = new ModInfo(); - i.location = f; - List m = C.GSON.fromJson(new InputStreamReader(jar.getInputStream(entry), "UTF-8"), TYPE); - if (m != null && m.size() > 0) { - i = m.get(0); - i.location = f; - } - return i; + ModInfo i = new ModInfo(); + i.location = f; + + InputStreamReader streamReader = new InputStreamReader(jar.getInputStream(entry), "UTF-8"); + + JsonParser parser = new JsonParser(); + JsonElement element = parser.parse(streamReader); + List m = null; + if (element.isJsonArray()) { + m = C.GSON.fromJson(element, new TypeToken>(){}.getType()); + } else if (element.isJsonObject()) { + JsonObject modInfo = element.getAsJsonObject(); + if (modInfo.has("modList") && modInfo.get("modList").isJsonArray()) { + m = C.GSON.fromJson(modInfo.get("modList"), new TypeToken>(){}.getType()); + } + } + + if (m != null && m.size() > 0) { + i = m.get(0); + i.location = f; + } + + return i; } private static ModInfo getLiteLoaderModInfo(File f, ZipFile jar, ZipEntry entry) throws IOException {