Skip to content

Commit

Permalink
Document the kind of URL that is resolved.
Browse files Browse the repository at this point in the history
Use pre-resolved minecraft versions if possible.
  • Loading branch information
marchermans committed Apr 27, 2024
1 parent e301768 commit 3bc21bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ public final Map<GameArtifact, File> cacheGameVersion(String gameVersion, Distri

final Map<GameArtifact, File> result = new EnumMap<>(GameArtifact.class);

GameArtifact.VERSION_MANIFEST.doWhenRequired(side, () -> result.put(GameArtifact.VERSION_MANIFEST, this.cacheVersionManifest(resolvedVersion.getVersion())));
GameArtifact.CLIENT_JAR.doWhenRequired(side, () -> result.put(GameArtifact.CLIENT_JAR, this.cacheVersionArtifact(resolvedVersion.getVersion(), DistributionType.CLIENT)));
GameArtifact.SERVER_JAR.doWhenRequired(side, () -> result.put(GameArtifact.SERVER_JAR, this.cacheVersionArtifact(resolvedVersion.getVersion(), DistributionType.SERVER)));
GameArtifact.CLIENT_MAPPINGS.doWhenRequired(side, () -> result.put(GameArtifact.CLIENT_MAPPINGS, this.cacheVersionMappings(resolvedVersion.getVersion(), DistributionType.CLIENT)));
GameArtifact.SERVER_MAPPINGS.doWhenRequired(side, () -> result.put(GameArtifact.SERVER_MAPPINGS, this.cacheVersionMappings(resolvedVersion.getVersion(), DistributionType.SERVER)));
GameArtifact.VERSION_MANIFEST.doWhenRequired(side, () -> result.put(GameArtifact.VERSION_MANIFEST, this.cacheVersionManifest(resolvedVersion)));
GameArtifact.CLIENT_JAR.doWhenRequired(side, () -> result.put(GameArtifact.CLIENT_JAR, this.cacheVersionArtifact(resolvedVersion, DistributionType.CLIENT)));
GameArtifact.SERVER_JAR.doWhenRequired(side, () -> result.put(GameArtifact.SERVER_JAR, this.cacheVersionArtifact(resolvedVersion, DistributionType.SERVER)));
GameArtifact.CLIENT_MAPPINGS.doWhenRequired(side, () -> result.put(GameArtifact.CLIENT_MAPPINGS, this.cacheVersionMappings(resolvedVersion, DistributionType.CLIENT)));
GameArtifact.SERVER_MAPPINGS.doWhenRequired(side, () -> result.put(GameArtifact.SERVER_MAPPINGS, this.cacheVersionMappings(resolvedVersion, DistributionType.SERVER)));

return result;
}
Expand Down Expand Up @@ -133,6 +133,10 @@ public final File cacheLauncherMetadata() {
public final File cacheVersionManifest(String gameVersion) {
final MinecraftVersionAndUrl resolvedVersion = resolveVersion(gameVersion);

return this.cacheVersionManifest(resolvedVersion);
}

public final File cacheVersionManifest(MinecraftVersionAndUrl resolvedVersion) {
final CacheFileSelector cacheFileSelector = CacheFileSelector.forVersionJson(resolvedVersion.getVersion());
return this.cacheFiles.computeIfAbsent(cacheFileSelector, selector -> downloadVersionManifestToCache(project, getCacheDirectory().get().getAsFile(), resolvedVersion.getVersion()));
}
Expand All @@ -145,6 +149,11 @@ public final File cacheVersionArtifact(String gameVersion, DistributionType side
return this.cacheFiles.computeIfAbsent(cacheFileSelector, selector -> downloadVersionArtifactToCache(project, getCacheDirectory().get().getAsFile(), resolvedVersion.getVersion(), side));
}

public final File cacheVersionArtifact(MinecraftVersionAndUrl resolvedVersion, DistributionType side) {
final CacheFileSelector cacheFileSelector = CacheFileSelector.forVersionJar(resolvedVersion.getVersion(), side.getName());
return this.cacheFiles.computeIfAbsent(cacheFileSelector, selector -> downloadVersionArtifactToCache(project, getCacheDirectory().get().getAsFile(), resolvedVersion.getVersion(), side));
}

@Override
public final File cacheVersionMappings(@NotNull String gameVersion, DistributionType side) {
final MinecraftVersionAndUrl resolvedVersion = resolveVersion(gameVersion);
Expand All @@ -153,6 +162,11 @@ public final File cacheVersionMappings(@NotNull String gameVersion, Distribution
return this.cacheFiles.computeIfAbsent(cacheFileSelector, selector -> downloadVersionMappingsToCache(project, getCacheDirectory().get().getAsFile(), resolvedVersion.getVersion(), side));
}

public final File cacheVersionMappings(@NotNull MinecraftVersionAndUrl resolvedVersion, DistributionType side) {
final CacheFileSelector cacheFileSelector = CacheFileSelector.forVersionMappings(resolvedVersion.getVersion(), side.getName());
return this.cacheFiles.computeIfAbsent(cacheFileSelector, selector -> downloadVersionMappingsToCache(project, getCacheDirectory().get().getAsFile(), resolvedVersion.getVersion(), side));
}

@Override
public final File cache(final URL url, final CacheFileSelector selector) {
return this.cache(url.toString(), selector);
Expand Down Expand Up @@ -210,7 +224,7 @@ private File downloadVersionMappingsToCache(final Project project, final File ca
private File doDownloadVersionDownloadToCache(Project project, File cacheDirectory, String minecraftVersion, final String artifact, final CacheFileSelector cacheFileSelector, final String potentialError) {
final MinecraftVersionAndUrl minecraftVersionAndUrl = resolveVersion(minecraftVersion);

final File versionManifestFile = this.cacheVersionManifest(minecraftVersionAndUrl.getVersion());
final File versionManifestFile = this.cacheVersionManifest(minecraftVersionAndUrl);

try {
JsonObject json = SerializationUtils.fromJson(versionManifestFile, JsonObject.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class MinecraftVersionAndUrl {
}

/**
* The url to download the minecraft version from.
* The url to download the version manifest file for the minecraft version from.
*
* @return The url to download the minecraft version from.
* @return The url to download the version manifest file for the minecraft version from
*/
String getUrl() {
return url
Expand Down

0 comments on commit 3bc21bd

Please sign in to comment.