modmuss50 / mod-publish-plugin

A Gradle plugin to publish mods to a range of destinations
https://modmuss50.github.io/mod-publish-plugin/
MIT License
50 stars 7 forks source link

allow specifying a version range #22

Closed AnAwesomGuy closed 9 months ago

AnAwesomGuy commented 9 months ago

so, for example, i could do 1.18,1.19.2 and it would add all the versions and snapshots between those versions (inclusive) right now, i have this terrible thing in my build.gradle

BufferedReader br = new BufferedReader(new InputStreamReader(System.in))
println "Enter version range (inclusive) (separated by a comma, like this: 1.18,1.19.2):"
String[] range = br.readLine().replace(' ', '').split(',')
if (range.length != 2)
    throw new IllegalArgumentException("Version range is incorrect! Should be of form: 1.18,1.19.2.")
String minecraftVersionsList = "https://piston-meta.mojang.com/mc/game/version_manifest.json"
ArrayList<String> modrinthVersions = [], cfVersions = []
try (InputStreamReader reader = new InputStreamReader(minecraftVersionsList.toURL().openStream())) {
    boolean matches
    JsonObject jsonObject = new Gson().fromJson(reader, JsonElement.class).asJsonObject
    for (JsonObject versionObject : (jsonObject.getAsJsonArray('versions') as Iterable<JsonObject>)) {
        String version = versionObject.getAsJsonPrimitive('id').asString
        if (version == range[0])
            matches = true
        if (matches) {
            if (versionObject.getAsJsonPrimitive('type').asString == "release")
                releases.add(version)
            modrinthVersions.add(version)
        }
        if (version == range[1])
            break
    }
} catch (IOException e) {
    throw new RuntimeException("Could not fetch Minecraft versions list.", e)
} catch (ClassCastException | IllegalStateException e) {
    throw new RuntimeException("The Minecraft versions list has most likely changed from when I wrote this! Please make a PR on Github to fix this", e)
}

for curseforge, maybe you could loop over the result of issuing a get request to minecraft.curseforge.com/api/game/versions and do a similar thing to what i did with the minecraft versions list i would have definitely made a pr if i understood kotlin lol

AnAwesomGuy commented 9 months ago

also, if it's possible to automatically make the newest version featured, that would be amazing

modmuss50 commented 9 months ago

I think a version range may be possible for modrinth, curseforge will be a bit harder as it doesnt follow the standard Minecraft versioning.

modmuss50 commented 9 months ago

Done, thanks for the idea.