Created
January 17, 2021 03:47
-
-
Save dexman545/6461b5fe75e617328c7faafb6091ced3 to your computer and use it in GitHub Desktop.
Gradle scripts to make pulling data easier for Fabric mods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
dependencies { | |
classpath "com.github.yuchi:npm-semver:1.0.0" | |
} | |
} | |
import com.github.yuchi.semver.Version | |
import groovy.json.JsonSlurper | |
import java.util.regex.Matcher | |
import java.util.regex.Pattern | |
/** | |
* Get the newest available loader version. | |
* | |
* @return loader version. | |
*/ | |
static String getNewestLoaderVersion() { | |
def loaderVersions = new JsonSlurper().parse(new URL("https://meta.fabricmc.net/v2/versions/loader/")) | |
assert loaderVersions instanceof ArrayList<LinkedHashMap> // Type check to to remove visual errors | |
return loaderVersions.first().version | |
} | |
/** | |
* Get correct Yarn version for project's MC version. | |
* | |
* @param newest whether to return the newest available Yarn version, or the oldest. Oldest may be preferred to avoid | |
* invalidating genSources' output. | |
* @return the correct Yarn version. | |
*/ | |
String getChosenYarnVersion(boolean newest) { | |
def yarnVersions = new JsonSlurper().parse( | |
new URL("https://meta.fabricmc.net/v2/versions/yarn/${project.minecraft_version}")) | |
assert yarnVersions instanceof ArrayList<LinkedHashMap> // Type check to to remove visual errors | |
return newest ? yarnVersions.first().version : yarnVersions.last().version | |
} | |
/** | |
* Get the latest MC version. | |
* | |
* @param isStable if snapshots should be ignored or not. | |
* @return the MC version. | |
*/ | |
static String getLatestMc(boolean isStable) { | |
def mcVersions = new JsonSlurper().parse(new URL("https://meta.fabricmc.net/v2/versions/game")) | |
assert mcVersions instanceof ArrayList<LinkedHashMap> // Type check to to remove visual errors | |
if (!isStable) return mcVersions.first().version | |
for (LinkedHashMap mcVer : mcVersions) { | |
if (mcVer.stable) return mcVer.version | |
} | |
return "" // No MC version was found | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment