diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java index 61674d3ed9..8f6cf7913f 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModListPageSkin.java @@ -278,7 +278,7 @@ static class ModInfoObject extends RecursiveTreeObject implements message.append(", ").append(i18n("archive.author")).append(": ").append(localModFile.getAuthors()); this.message = message.toString(); - this.mod = ModTranslations.MOD.getModById(localModFile.getId()); + this.mod = ModTranslations.MOD.getMod(localModFile.getName(), localModFile.getId()); } String getTitle() { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModTranslations.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModTranslations.java index feddeea04a..2616072af9 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModTranslations.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModTranslations.java @@ -67,7 +67,7 @@ public static ModTranslations getTranslationsByRepositoryType(RemoteModRepositor private final String resourceName; private List mods; - private Map modIdMap; // mod id -> mod + private Map modMap; // mod id and subname -> mod private Map curseForgeMap; // curseforge id -> mod private List> keywords; private int maxKeywordLength = -1; @@ -84,10 +84,19 @@ public Mod getModByCurseForgeId(String id) { } @Nullable - public Mod getModById(String id) { - if (StringUtils.isBlank(id) || !loadModIdMap()) return null; + public Mod getMod(String subname, String id) { + if (!loadModMap()) return null; - return modIdMap.get(id); + if (StringUtils.isNotBlank(subname)) { + String filteredSubName = "subname-" + subname.replaceAll("[^a-zA-Z]", ""); + return modMap.get(filteredSubName); + } + + if (StringUtils.isNotBlank(id)) { + return modMap.get(id); + } + + return null; } public abstract String getMcmodUrl(Mod mod); @@ -149,8 +158,8 @@ private boolean loadCurseForgeMap() { return true; } - private boolean loadModIdMap() { - if (modIdMap != null) { + private boolean loadModMap() { + if (modMap != null) { return true; } @@ -158,11 +167,18 @@ private boolean loadModIdMap() { if (!loadFromResource()) return false; } - modIdMap = new HashMap<>(); + modMap = new HashMap<>(); for (Mod mod : mods) { + String subname = mod.getSubname(); + if (StringUtils.isNotBlank(subname) && !"examplemod".equals(subname)) { + String filteredSubName = "subname-" + subname.replaceAll("[^a-zA-Z]", ""); + if (!filteredSubName.isEmpty()) { + modMap.put(filteredSubName, mod); + } + } for (String id : mod.getModIds()) { if (StringUtils.isNotBlank(id) && !"examplemod".equals(id)) { - modIdMap.put(id, mod); + modMap.put(id, mod); } } }