Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ public Task<?> refreshAsync() {
lock.writeLock().lock();

try {
for (String gameVersion : gameVersions)
for (String loaderVersion : loaderVersions)
for (String metaGameVersion : gameVersions) {
String gameVersion = normalizeVersion(metaGameVersion);
for (String loaderVersion : loaderVersions) {
versions.put(gameVersion, new LegacyFabricRemoteVersion(gameVersion, loaderVersion,
Collections.singletonList(getLaunchMetaUrl(gameVersion, loaderVersion))));
Collections.singletonList(getLaunchMetaUrl(metaGameVersion, loaderVersion))));
}
}
} finally {
lock.writeLock().unlock();
}
Expand All @@ -71,6 +74,12 @@ private List<String> getGameVersions(String metaUrl) throws IOException {
.stream().map(GameVersion::getVersion).collect(Collectors.toList());
}

private static String normalizeVersion(String version) {
return version.startsWith("2point0_")
? "2.0_" + version.substring("2point0_".length())
: version;
}
Comment on lines +77 to +81
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这个 normalizeVersion 方法目前仅处理了带有下划线的前缀 2point0_。虽然目前 Legacy Fabric 的 Meta API 可能主要返回这种格式,但为了提高代码的健壮性,建议也处理一下不带下划线的情况(例如直接是 2point0),以防未来 API 返回格式发生变化。

Suggested change
private static String normalizeVersion(String version) {
return version.startsWith("2point0_")
? "2.0_" + version.substring("2point0_".length())
: version;
}
private static String normalizeVersion(String version) {
if (version.startsWith("2point0_")) {
return "2.0_" + version.substring("2point0_".length());
}
return "2point0".equals(version) ? "2.0" : version;
}


private static String getLaunchMetaUrl(String gameVersion, String loaderVersion) {
return String.format("https://meta.legacyfabric.net/v2/versions/loader/%s/%s", gameVersion, loaderVersion);
}
Expand Down