Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Commit 0c946cc

Browse files
committed
Style[bta_profile]: improve code niceness
1 parent 61c8e57 commit 0c946cc

File tree

1 file changed

+27
-13
lines changed
  • app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders

1 file changed

+27
-13
lines changed

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/modloaders/BTAUtils.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
import java.util.ListIterator;
1717

1818
public class BTAUtils {
19-
private static final String BTA_CLIENT_URL = "https://downloads.betterthanadventure.net/bta-client/%s/%s/client.jar";
20-
private static final String BTA_ICON_URL = "https://downloads.betterthanadventure.net/bta-client/%s/%s/auto/%s.png";
19+
private static final String BASE_DOWNLOADS_URL = "https://downloads.betterthanadventure.net/bta-client/";
20+
private static final String CLIENT_JAR_URL = BASE_DOWNLOADS_URL + "%s/%s/client.jar";
21+
private static final String ICON_URL = BASE_DOWNLOADS_URL + "%s/%s/auto/%s.png";
22+
private static final String MANIFEST_URL = BASE_DOWNLOADS_URL + "%s/versions.json";
23+
private static final String BUILD_TYPE_RELEASE = "release";
24+
private static final String BUILD_TYPE_NIGHTLY = "nightly";
2125
private static final List<String> BTA_TESTED_VERSIONS = new ArrayList<>();
2226
static {
2327
BTA_TESTED_VERSIONS.add("v7.3");
@@ -30,7 +34,21 @@ public class BTAUtils {
3034
private static String getIconUrl(String version, String buildType) {
3135
String iconName = version.replace('.','_');
3236
if(buildType.equals("nightly")) iconName = "v"+iconName;
33-
return String.format(BTA_ICON_URL, buildType, version, iconName);
37+
return String.format(ICON_URL, buildType, version, iconName);
38+
}
39+
40+
private static String getClientJarUrl(String version, String buildType) {
41+
return String.format(CLIENT_JAR_URL, buildType, version);
42+
}
43+
44+
private static String getManifestUrl(String buildType) {
45+
return String.format(MANIFEST_URL, buildType);
46+
}
47+
48+
private static <T> T getManifest(String buildType, DownloadUtils.ParseCallback<T> parser)
49+
throws DownloadUtils.ParseException, IOException {
50+
String manifestUrl = getManifestUrl(buildType);
51+
return DownloadUtils.downloadStringCached(manifestUrl,"bta_"+manifestUrl, parser);
3452
}
3553

3654
private static List<BTAVersion> createVersionList(List<String> versionStrings, String buildType) {
@@ -41,7 +59,7 @@ private static List<BTAVersion> createVersionList(List<String> versionStrings, S
4159
if(version == null) continue;
4260
btaVersions.add(new BTAVersion(
4361
version,
44-
String.format(BTA_CLIENT_URL, buildType, version),
62+
getClientJarUrl(version, buildType),
4563
getIconUrl(version, buildType)
4664
));
4765
}
@@ -51,7 +69,7 @@ private static List<BTAVersion> createVersionList(List<String> versionStrings, S
5169

5270
private static List<BTAVersion> processNightliesJson(String nightliesInfo) throws JsonParseException {
5371
BTAVersionsManifest manifest = Tools.GLOBAL_GSON.fromJson(nightliesInfo, BTAVersionsManifest.class);
54-
return createVersionList(manifest.versions, "nightly");
72+
return createVersionList(manifest.versions, BUILD_TYPE_NIGHTLY);
5573
}
5674

5775
private static BTAVersionList processReleasesJson(String releasesInfo) throws JsonParseException {
@@ -69,20 +87,16 @@ private static BTAVersionList processReleasesJson(String releasesInfo) throws Js
6987
}
7088

7189
return new BTAVersionList(
72-
createVersionList(testedVersions, "release"),
73-
createVersionList(untestedVersions, "release"),
90+
createVersionList(testedVersions, BUILD_TYPE_RELEASE),
91+
createVersionList(untestedVersions, BUILD_TYPE_RELEASE),
7492
null
7593
);
7694
}
7795

7896
public static BTAVersionList downloadVersionList() throws IOException {
7997
try {
80-
BTAVersionList releases = DownloadUtils.downloadStringCached(
81-
"https://downloads.betterthanadventure.net/bta-client/release/versions.json",
82-
"bta_releases", BTAUtils::processReleasesJson);
83-
List<BTAVersion> nightlies = DownloadUtils.downloadStringCached(
84-
"https://downloads.betterthanadventure.net/bta-client/nightly/versions.json",
85-
"bta_nightlies", BTAUtils::processNightliesJson);
98+
BTAVersionList releases = getManifest(BUILD_TYPE_RELEASE, BTAUtils::processReleasesJson);
99+
List<BTAVersion> nightlies = getManifest(BUILD_TYPE_NIGHTLY, BTAUtils::processNightliesJson);
86100
return new BTAVersionList(releases.testedVersions, releases.untestedVersions, nightlies);
87101
}catch (DownloadUtils.ParseException e) {
88102
Log.e("BTAUtils", "Failed to process json", e);

0 commit comments

Comments
 (0)