Skip to content

Commit

Permalink
auto version discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysdh540 committed Oct 13, 2023
1 parent 6105c88 commit 1b02fca
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
3 changes: 0 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ shadow_version=8.1.1
# the mc version to compile against (see their respective property files for version-specific stuff)
mcVer=1.19.2

# which versions to put in the build.properties file
mc_versions=1.19.2, 1.20.1

# which version to use if mcVer is invalid/not in mc_versions
default_mc_version=1.19.2

Expand Down
14 changes: 10 additions & 4 deletions gradle/preprocessor.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
def mcVersion = ""
def mcVers = mc_versions.split(", ").toList()

def mcVers = rootProject.fileTree('versionProperties').files.name
for(int i = 0; i < mcVers.size(); i++) {
mcVers[i] = mcVers[i].replaceAll('\\.properties', '')
}
mcVers.sort()

int mcIndex = -1

println "Setting up preprocessor...\nAvalible Minecraft Versions: ${mc_versions}"
println "Setting up preprocessor...\nAvalible Minecraft Versions: ${mcVers.join(', ')}"

if (project.hasProperty("mcVer")) {
mcVersion = mcVer
mcIndex = mcVers.indexOf(mcVer)
}

if (mcIndex == -1) {
println "Defaulting to ${default_mc_version} since the set mcVer is invalid."
println "No mcVer set or the set mcVer is invalid! Defaulting to ${default_mc_version}."
println "Use -PmcVer='${default_mc_version}' or edit gradle.properties to set the minecraft version."

mcVersion = default_mc_version
Expand All @@ -21,7 +27,7 @@ if (mcIndex == -1) {

def properties = new Properties()

properties.load(new FileInputStream("$rootProject.rootDir/"+"$mcVersion"+".properties"))
properties.load(new FileInputStream("$rootProject.rootDir/versionProperties/"+"$mcVersion"+".properties"))

properties.each {
ext.set(it.key, it.value)
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 1b02fca

Please sign in to comment.