Skip to content
Merged
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
37 changes: 18 additions & 19 deletions src/main/java/net/ornithemc/meta/data/VersionDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@

package net.ornithemc.meta.data;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.ornithemc.meta.OrnitheMeta;
import net.ornithemc.meta.utils.MinecraftLauncherMeta;
import net.ornithemc.meta.utils.MavenPomParser;
import net.ornithemc.meta.utils.MavenMetadataParser;
import net.ornithemc.meta.utils.MavenMetadataParser.StableVersionIdentifier;
Expand All @@ -43,7 +41,6 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@JsonIgnoreProperties({"manifest"})
public class VersionDatabase {

public static final String FABRIC_MAVEN_URL = "https://maven.fabricmc.net/";
Expand Down Expand Up @@ -162,7 +159,7 @@ private static List<String> oslModules(int generation) {
return modules;
}

public final VersionManifest manifest;
private final Int2ObjectMap<VersionManifest> manifests;
private final Int2ObjectMap<List<BaseVersion>> game;
private final Int2ObjectMap<List<MavenVersion>> intermediary;
private final Int2ObjectMap<List<MavenBuildGameVersion>> feather;
Expand All @@ -178,7 +175,7 @@ private static List<String> oslModules(int generation) {
public List<LibraryUpgrade> libraryUpgrades;

private VersionDatabase() {
this.manifest = new VersionManifest();
this.manifests = new Int2ObjectOpenHashMap<>();
this.game = new Int2ObjectOpenHashMap<>();
this.intermediary = new Int2ObjectOpenHashMap<>();
this.feather = new Int2ObjectOpenHashMap<>();
Expand All @@ -193,6 +190,7 @@ public static VersionDatabase generate() throws Exception {
VersionDatabase database = new VersionDatabase();
config = ConfigV3.load();
for (int generation = 1; generation <= config.latestIntermediaryGeneration; generation++) {
database.manifests.put(generation, VersionManifest.forGenSorted(generation));
database.intermediary.put(generation, intermediaryMetadataParser(generation).getVersions(MavenVersion::new));
database.feather.put(generation, featherMetadataParser(generation).getVersions(MavenBuildGameVersion::new));
database.osl.put(generation, oslMetadataParser(generation).getVersions(MavenVersion::new));
Expand All @@ -212,7 +210,7 @@ public static VersionDatabase generate() throws Exception {
database.sparrow = SPARROW_METADATA_PARSER.getVersions(MavenBuildGameVersion::new);
database.nests = NESTS_METADATA_PARSER.getVersions(MavenBuildGameVersion::new);
database.installer = INSTALLER_METADATA_PARSER.getVersions(MavenUrlVersion::new);
database.libraryUpgrades = LibraryUpgradesV3.get();
database.libraryUpgrades = LibraryUpgradesV3.reload();
database.loadMcData();
OrnitheMeta.LOGGER.info("DB update took {}ms", System.currentTimeMillis() - start);
return database;
Expand All @@ -228,21 +226,18 @@ private void loadMcData() throws IOException {
throw new RuntimeException("Mappings are empty");
}

Int2ObjectMap<MinecraftLauncherMeta> launcherMetas = new Int2ObjectOpenHashMap<>();

for (int generation = 1; generation <= config.latestIntermediaryGeneration; generation++) {
final int gen = generation;
final MinecraftLauncherMeta launcherMeta = MinecraftLauncherMeta.getSortedMeta(gen);
launcherMetas.put(generation, launcherMeta);
final VersionManifest manifest = manifests.get(generation);
intermediary.compute(generation, (key, value) -> {
// Sorts in the order of minecraft release dates
value = new ArrayList<>(value);
value.sort(Comparator.comparingInt(o -> launcherMeta.getIndex(o.getVersionNoSide())));
value.sort(Comparator.comparingInt(o -> manifest.indexOf(o.getVersionNoSide())));
value.forEach(version -> version.setStable(true));

// Remove entries that do not match a valid mc version.
value.removeIf(o -> {
if (launcherMeta.getVersions().stream().noneMatch(metaVersion -> metaVersion.getId().equals(o.getVersionNoSide()))) {
if (!manifest.contains(o.getVersionNoSide())) {
OrnitheMeta.LOGGER.info("Removing {} from intermediary v3{} as it does not match a mc version", o.getVersion(), (gen < 1 ? "" : " gen" + gen));
return true;
}
Expand All @@ -254,12 +249,12 @@ private void loadMcData() throws IOException {
feather.compute(generation, (key, value) -> {
// Sorts in the order of minecraft release dates
value = new ArrayList<>(value);
value.sort(Comparator.comparingInt(o -> launcherMeta.getIndex(o.getVersionNoSide())));
value.sort(Comparator.comparingInt(o -> manifest.indexOf(o.getVersionNoSide())));
value.forEach(version -> version.setStable(true));

// Remove entries that do not match a valid mc version.
value.removeIf(o -> {
if (launcherMeta.getVersions().stream().noneMatch(metaVersion -> metaVersion.getId().equals(o.getVersionNoSide()))) {
if (!manifest.contains(o.getVersionNoSide())) {
OrnitheMeta.LOGGER.info("Removing {} from v3 feather gen{} as it does not match a mc version", o.getGameVersion(), gen);
return true;
}
Expand All @@ -276,13 +271,13 @@ private void loadMcData() throws IOException {
}
}

game.put(generation, minecraftVersions.stream().map(s -> new BaseVersion(s, launcherMeta.isStable(s))).collect(Collectors.toList()));
game.put(generation, minecraftVersions.stream().map(s -> new BaseVersion(s, manifest.isStable(s))).collect(Collectors.toList()));
}

Function<String, Predicate<MavenBuildGameVersion>> p = src -> {
return o -> {
for (int generation = 1; generation <= config.latestIntermediaryGeneration; generation++) {
if (launcherMetas.get(generation).getVersions().stream().anyMatch(metaVersion -> metaVersion.getId().equals(o.getVersionNoSide()))) {
if (manifests.get(generation).contains(o.getVersionNoSide())) {
return false;
}
}
Expand All @@ -294,9 +289,9 @@ private void loadMcData() throws IOException {
int i1 = Integer.MAX_VALUE;
int i2 = Integer.MAX_VALUE;
for (int generation = 1; generation <= config.latestIntermediaryGeneration; generation++) {
MinecraftLauncherMeta launcherMeta = launcherMetas.get(generation);
i1 = Math.min(i1, launcherMeta.getIndex(v1.getVersionNoSide()));
i2 = Math.min(i2, launcherMeta.getIndex(v2.getVersionNoSide()));
VersionManifest manifest = manifests.get(generation);
i1 = Math.min(i1, manifest.indexOf(v1.getVersionNoSide()));
i2 = Math.min(i2, manifest.indexOf(v2.getVersionNoSide()));
}
return Integer.compare(i1, i2);
};
Expand All @@ -316,6 +311,10 @@ private void loadMcData() throws IOException {
nests.removeIf(p.apply("v3 nests"));
}

public VersionManifest getManifest(int generation) {
return manifests.get(generation);
}

public List<BaseVersion> getGame(int generation) {
return game.get(generation);
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/ornithemc/meta/data/VersionDatabaseOld.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package net.ornithemc.meta.data;

import net.ornithemc.meta.OrnitheMeta;
import net.ornithemc.meta.utils.MinecraftLauncherMeta;
import net.ornithemc.meta.utils.MavenMetadataParser;
import net.ornithemc.meta.utils.VersionManifest;
import net.ornithemc.meta.web.models.BaseVersion;
import net.ornithemc.meta.web.models.MavenBuildVersion;
import net.ornithemc.meta.web.models.MavenUrlVersion;
Expand Down Expand Up @@ -72,11 +72,11 @@ private void loadMcData() throws IOException {
if (calamus == null) {
throw new RuntimeException("Mappings are null");
}
MinecraftLauncherMeta launcherMeta = MinecraftLauncherMeta.getSortedMeta(1);
VersionManifest manifest = VersionManifest.forGenSorted(1);

//Sorts in the order of minecraft release dates
calamus = new ArrayList<>(calamus);
calamus.sort(Comparator.comparingInt(o -> launcherMeta.getIndex(o.getVersion())));
calamus.sort(Comparator.comparingInt(o -> manifest.indexOf(o.getVersion())));
calamus.forEach(version -> version.setStable(true));

// Remove entries that do not match a valid mc version.
Expand All @@ -88,7 +88,7 @@ private void loadMcData() throws IOException {
iVersion = o.getVersion();
}

if (launcherMeta.getVersions().stream().noneMatch(metaVersion -> metaVersion.getId().equals(iVersion))) {
if (!manifest.contains(iVersion)) {
OrnitheMeta.LOGGER.info("Removing {} as it is not match an mc version (v2)", o.getVersion());
return true;
}
Expand All @@ -102,7 +102,7 @@ private void loadMcData() throws IOException {
}
}

game = minecraftVersions.stream().map(s -> new BaseVersion(s, launcherMeta.isStable(s))).collect(Collectors.toList());
game = minecraftVersions.stream().map(s -> new BaseVersion(s, manifest.isStable(s))).collect(Collectors.toList());
}

public List<MavenBuildVersion> getLoader() {
Expand Down
116 changes: 0 additions & 116 deletions src/main/java/net/ornithemc/meta/utils/MinecraftLauncherMeta.java

This file was deleted.

Loading