Skip to content
Closed
Show file tree
Hide file tree
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 @@ -43,15 +43,7 @@ public boolean hasType() {
return false;
}

private static final class LiteLoaderBMCLVersion {

private final LiteLoaderVersion build;
private final String version;

public LiteLoaderBMCLVersion(LiteLoaderVersion build, String version) {
this.build = build;
this.version = version;
}
private record LiteLoaderBMCLVersion(LiteLoaderVersion build, String version) {
}

@Override
Expand All @@ -78,7 +70,7 @@ public Task<?> refreshAsync(String gameVersion) {
downloadProvider.getApiRoot() + "/liteloader/download",
Collections.singletonMap("version", v.version)
)),
v.build.getTweakClass(), v.build.getLibraries()
v.build.tweakClass(), v.build.libraries()
));
} finally {
lock.writeLock().unlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,11 @@
* @author huangyuhui
*/
@Immutable
public final class LiteLoaderBranch {
public record LiteLoaderBranch(@SerializedName("libraries") Collection<Library> libraries,
@SerializedName("com.mumfrey:liteloader") Map<String, LiteLoaderVersion> liteLoader) {

@SerializedName("libraries")
private final Collection<Library> libraries;

@SerializedName("com.mumfrey:liteloader")
private final Map<String, LiteLoaderVersion> liteLoader;

/**
* No-arg constructor for Gson.
*/
@SuppressWarnings("unused")
public LiteLoaderBranch() {
this(Collections.emptySet(), Collections.emptyMap());
public LiteLoaderBranch {
libraries = libraries == null ? Collections.emptySet() : Collections.unmodifiableCollection(libraries);
liteLoader = liteLoader == null ? Collections.emptyMap() : Collections.unmodifiableMap(liteLoader);
}

public LiteLoaderBranch(Collection<Library> libraries, Map<String, LiteLoaderVersion> liteLoader) {
this.libraries = libraries;
this.liteLoader = liteLoader;
}

public Collection<Library> getLibraries() {
return Collections.unmodifiableCollection(libraries);
}

public Map<String, LiteLoaderVersion> getLiteLoader() {
return Collections.unmodifiableMap(liteLoader);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,7 @@
* @author huangyuhui
*/
@Immutable
public final class LiteLoaderGameVersions {

@SerializedName("repo")
private final LiteLoaderRepository repoitory;

@SerializedName("artefacts")
private final LiteLoaderBranch artifacts;

@SerializedName("snapshots")
private final LiteLoaderBranch snapshots;

/**
* No-arg constructor for Gson.
*/
@SuppressWarnings("unused")
public LiteLoaderGameVersions() {
this(null, null, null);
}

public LiteLoaderGameVersions(LiteLoaderRepository repoitory, LiteLoaderBranch artifacts, LiteLoaderBranch snapshots) {
this.repoitory = repoitory;
this.artifacts = artifacts;
this.snapshots = snapshots;
}

public LiteLoaderRepository getRepoitory() {
return repoitory;
}

public LiteLoaderBranch getArtifacts() {
return artifacts;
}

public LiteLoaderBranch getSnapshots() {
return snapshots;
}

public record LiteLoaderGameVersions(@SerializedName("repo") LiteLoaderRepository repoitory,
@SerializedName("artefacts") LiteLoaderBranch artifacts,
@SerializedName("snapshots") LiteLoaderBranch snapshots) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,49 +25,13 @@
* @author huangyuhui
*/
@Immutable
public final class LiteLoaderRepository {

@SerializedName("stream")
private final String stream;

@SerializedName("type")
private final String type;

@SerializedName("url")
private final String url;

@SerializedName("classifier")
private final String classifier;

/**
* No-arg constructor for Gson.
*/
@SuppressWarnings("unused")
public LiteLoaderRepository() {
this("", "", "", "");
}

public LiteLoaderRepository(String stream, String type, String url, String classifier) {
this.stream = stream;
this.type = type;
this.url = url;
this.classifier = classifier;
}

public String getStream() {
return stream;
}

public String getType() {
return type;
}

public String getUrl() {
return url;
}

public String getClassifier() {
return classifier;
public record LiteLoaderRepository(@SerializedName("stream") String stream, @SerializedName("type") String type,
@SerializedName("url") String url, @SerializedName("classifier") String classifier) {

public LiteLoaderRepository {
if (stream == null) stream = "";
if (type == null) type = "";
if (url == null) url = "";
if (classifier == null) classifier = "";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,59 +28,15 @@
* @author huangyuhui
*/
@Immutable
public final class LiteLoaderVersion {
private final String tweakClass;
private final String file;
private final String version;
private final String md5;
private final String timestamp;
private final int lastSuccessfulBuild;
private final Collection<Library> libraries;
public record LiteLoaderVersion(String tweakClass, String file, String version, String md5, String timestamp,
int lastSuccessfulBuild, Collection<Library> libraries) {

/**
* No-arg constructor for Gson.
*/
@SuppressWarnings("unused")
public LiteLoaderVersion() {
this("", "", "", "", "", 0, Collections.emptySet());
public LiteLoaderVersion {
if (tweakClass == null) tweakClass = "";
if (file == null) file = "";
if (version == null) version = "";
if (md5 == null) md5 = "";
if (timestamp == null) timestamp = "";
libraries = libraries == null ? Collections.emptySet() : Collections.unmodifiableCollection(libraries);
}

public LiteLoaderVersion(String tweakClass, String file, String version, String md5, String timestamp, int lastSuccessfulBuild, Collection<Library> libraries) {
this.tweakClass = tweakClass;
this.file = file;
this.version = version;
this.md5 = md5;
this.timestamp = timestamp;
this.lastSuccessfulBuild = lastSuccessfulBuild;
this.libraries = libraries;
}

public String getTweakClass() {
return tweakClass;
}

public String getFile() {
return file;
}

public String getVersion() {
return version;
}

public String getMd5() {
return md5;
}

public String getTimestamp() {
return timestamp;
}

public int getLastSuccessfulBuild() {
return lastSuccessfulBuild;
}

public Collection<Library> getLibraries() {
return Collections.unmodifiableCollection(libraries);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ public Task<?> refreshAsync(String gameVersion) {
return new GetTask(downloadProvider.injectURLWithCandidates(LITELOADER_LIST))
.thenGetJsonAsync(LiteLoaderVersionsRoot.class)
.thenAcceptAsync(root -> {
LiteLoaderGameVersions versions = root.getVersions().get(gameVersion);
LiteLoaderGameVersions versions = root.versions().get(gameVersion);
if (versions == null) {
return;
}

LiteLoaderRemoteVersion snapshot = null;
if (versions.getSnapshots() != null) {
if (versions.snapshots() != null) {
try {
snapshot = loadSnapshotVersion(gameVersion, versions.getSnapshots().getLiteLoader().get("latest"));
snapshot = loadSnapshotVersion(gameVersion, versions.snapshots().liteLoader().get("latest"));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand All @@ -73,8 +73,8 @@ public Task<?> refreshAsync(String gameVersion) {
try {
this.versions.clear();

if (versions.getRepoitory() != null && versions.getArtifacts() != null) {
loadArtifactVersion(gameVersion, versions.getRepoitory(), versions.getArtifacts());
if (versions.repoitory() != null && versions.artifacts() != null) {
loadArtifactVersion(gameVersion, versions.repoitory(), versions.artifacts());
}

if (snapshot != null) {
Expand All @@ -92,16 +92,16 @@ public Task<?> refreshAsync() {
}

private void loadArtifactVersion(String gameVersion, LiteLoaderRepository repository, LiteLoaderBranch branch) {
for (Map.Entry<String, LiteLoaderVersion> entry : branch.getLiteLoader().entrySet()) {
for (Map.Entry<String, LiteLoaderVersion> entry : branch.liteLoader().entrySet()) {
String branchName = entry.getKey();
LiteLoaderVersion v = entry.getValue();
if ("latest".equals(branchName))
continue;

versions.put(gameVersion, new LiteLoaderRemoteVersion(
gameVersion, v.getVersion(), RemoteVersion.Type.RELEASE,
Collections.singletonList(repository.getUrl() + "com/mumfrey/liteloader/" + gameVersion + "/" + v.getFile()),
v.getTweakClass(), v.getLibraries()
gameVersion, v.version(), RemoteVersion.Type.RELEASE,
Collections.singletonList(repository.url() + "com/mumfrey/liteloader/" + gameVersion + "/" + v.file()),
v.tweakClass(), v.libraries()
));
}
}
Expand All @@ -119,7 +119,7 @@ private LiteLoaderRemoteVersion loadSnapshotVersion(String gameVersion, LiteLoad
return new LiteLoaderRemoteVersion(
gameVersion, timestamp + "-" + buildNumber, RemoteVersion.Type.SNAPSHOT,
Collections.singletonList(String.format(SNAPSHOT_FILE, gameVersion, gameVersion, timestamp, buildNumber)),
v.getTweakClass(), v.getLibraries()
v.tweakClass(), v.libraries()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,12 @@
* @author huangyuhui
*/
@Immutable
public final class LiteLoaderVersionsMeta {
public record LiteLoaderVersionsMeta(@SerializedName("description") String description,
@SerializedName("authors") String authors, @SerializedName("url") String url) {

@SerializedName("description")
private final String description;

@SerializedName("authors")
private final String authors;

@SerializedName("url")
private final String url;

public LiteLoaderVersionsMeta() {
this("", "", "");
}

public LiteLoaderVersionsMeta(String description, String authors, String url) {
this.description = description;
this.authors = authors;
this.url = url;
}

public String getDescription() {
return description;
}

public String getAuthors() {
return authors;
public LiteLoaderVersionsMeta {
if (description == null) description = "";
if (authors == null) authors = "";
if (url == null) url = "";
}

public String getUrl() {
return url;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.gson.annotations.SerializedName;
import org.jackhuang.hmcl.util.Immutable;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.Map;
Expand All @@ -28,29 +29,10 @@
* @author huangyuhui
*/
@Immutable
public final class LiteLoaderVersionsRoot {
public record LiteLoaderVersionsRoot(@SerializedName("versions") Map<String, LiteLoaderGameVersions> versions,
@SerializedName("meta") @Nullable LiteLoaderVersionsMeta meta) {

@SerializedName("versions")
private final Map<String, LiteLoaderGameVersions> versions;

@SerializedName("meta")
private final LiteLoaderVersionsMeta meta;

public LiteLoaderVersionsRoot() {
this(Collections.emptyMap(), null);
public LiteLoaderVersionsRoot {
versions = versions == null ? Collections.emptyMap() : Collections.unmodifiableMap(versions);
}

public LiteLoaderVersionsRoot(Map<String, LiteLoaderGameVersions> versions, LiteLoaderVersionsMeta meta) {
this.versions = versions;
this.meta = meta;
}

public Map<String, LiteLoaderGameVersions> getVersions() {
return Collections.unmodifiableMap(versions);
}

public LiteLoaderVersionsMeta getMeta() {
return meta;
}

}