Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loader-style smever format MC versions #11

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ archivesBaseName = "fabric-meta"

repositories {
mavenCentral()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
}

dependencies {
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
implementation group: 'io.javalin', name: 'javalin', version: '3.13.3'
implementation group: 'io.javalin', name: 'javalin', version: '3.8.0'
implementation group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.30'
implementation group: 'commons-io', name: 'commons-io', version: '2.8.0'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
implementation group: 'net.fabricmc', name: 'fabric-loader', version: '0.11.3'
implementation group: 'org.ow2.asm', name: 'asm', version: '7.0'
}

jar {
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/net/fabricmc/meta/data/VersionDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package net.fabricmc.meta.data;

import net.fabricmc.loader.minecraft.McVersionLookup;
import net.fabricmc.meta.utils.MinecraftLauncherMeta;
import net.fabricmc.meta.utils.PomParser;
import net.fabricmc.meta.web.models.*;
Expand All @@ -25,7 +26,6 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class VersionDatabase {

Expand Down Expand Up @@ -86,7 +86,17 @@ private void loadMcData() throws IOException {
return 0;
});

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

private List<BaseVersion> getGameVersion(List<String> minecraftVersions, MinecraftLauncherMeta launcherMeta) {
List<BaseVersion> game = new ArrayList<>();
for (String s : minecraftVersions) {
game.add(new MinecraftVersion(s, launcherMeta.isStable(s),
McVersionLookup.getVersion(s).normalized));
}

return game;
}

}
30 changes: 29 additions & 1 deletion src/main/java/net/fabricmc/meta/utils/MinecraftLauncherMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
public class MinecraftLauncherMeta {

public static final Gson GSON = new GsonBuilder().create();
public static String json = "";

List<Version> versions;

Expand All @@ -36,14 +37,21 @@ private MinecraftLauncherMeta() {

public static MinecraftLauncherMeta getMeta() throws IOException {
String url = "https://launchermeta.mojang.com/mc/game/version_manifest.json";
String json = IOUtils.toString(new URL(url), StandardCharsets.UTF_8);
if (json.isEmpty()) json = IOUtils.toString(new URL(url), StandardCharsets.UTF_8);
return GSON.fromJson(json, MinecraftLauncherMeta.class);
}

public boolean isStable(String id) {
return versions.stream().anyMatch(version -> version.id.equals(id) && version.type.equals("release"));
}

public String majorVersion(String id) {
for (Version version : versions) {
if (version.id.equals(id)) return version.getTargetVersion();
}
return "";
}

public int getIndex(String version){
for (int i = 0; i < versions.size(); i++) {
if(versions.get(i).id.equals(version)){
Expand Down Expand Up @@ -80,6 +88,26 @@ public String getTime() {
public String getReleaseTime() {
return releaseTime;
}

public String getTargetVersion() {
String json = null;
try {
json = IOUtils.toString(new URL(url), StandardCharsets.UTF_8);
dexman545 marked this conversation as resolved.
Show resolved Hide resolved
return GSON.fromJson(json, Meta.class).getAssets();
} catch (IOException e) {
e.printStackTrace();
dexman545 marked this conversation as resolved.
Show resolved Hide resolved
return "";
}
}
}

public static class Meta {

String assets;
Copy link
Member

Choose a reason for hiding this comment

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

Im not sure the asset id always matches the target.

Copy link
Author

Choose a reason for hiding this comment

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

I haven't seen a case where it hasn't.
Here's the output it generates: https://gist.github.com/dexman545/4ad16ef4e1de9d10f9042b54fc5fd8ab


public String getAssets() {
return assets;
}
}

}
1 change: 1 addition & 0 deletions src/main/java/net/fabricmc/meta/web/EndpointsV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static void setup() {
WebServer.jsonGet("/v2/versions", () -> FabricMeta.database);

WebServer.jsonGet("/v2/versions/game", () -> FabricMeta.database.game);
WebServer.jsonGet("/v2/versions/game/:game_version", context -> filter(context, FabricMeta.database.game));
WebServer.jsonGet("/v2/versions/game/yarn", () -> compatibleGameVersions(FabricMeta.database.mappings, MavenBuildGameVersion::getGameVersion, v -> new BaseVersion(v.getGameVersion(), v.isStable())));
WebServer.jsonGet("/v2/versions/game/intermediary", () -> compatibleGameVersions(FabricMeta.database.intermediary, BaseVersion::getVersion, v -> new BaseVersion(v.getVersion(), v.isStable())));

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/fabricmc/meta/web/models/MinecraftVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.fabricmc.meta.web.models;

public class MinecraftVersion extends BaseVersion{
String semver;

public MinecraftVersion(String version, boolean stable, String semver) {
super(version, stable);
this.semver = semver;
}

public String getSemver() {
return semver;
}
}