Skip to content

Commit 888a6ba

Browse files
authored
Merge pull request #2 from MineBuilders/master
perf: cache the launcher while run server task
2 parents 1d27258 + 1193af8 commit 888a6ba

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

build.gradle.kts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,19 @@ tasks.register<Copy>("runServer") {
4040
val launcherRepo = "https://raw.githubusercontent.com/AllayMC/AllayLauncher/refs/heads/main/scripts"
4141
val cmdWin = "Invoke-Expression (Invoke-WebRequest -Uri \"${launcherRepo}/install_windows.ps1\").Content"
4242
val cmdLinux = "wget -qO- ${launcherRepo}/install_linux.sh | bash"
43-
val cwd = layout.buildDirectory.file("run").get().asFile.apply { mkdirs() }
43+
val cwd = layout.buildDirectory.file("run").get().asFile
4444

4545
val shadowJar = tasks.named("shadowJar", ShadowJar::class).get()
4646
from(shadowJar.archiveFile.get().asFile)
4747
into(cwd.resolve("plugins").apply { mkdirs() })
4848

49+
val isDownloaded = cwd.listFiles()!!.any { it.isFile && it.nameWithoutExtension == "allay" }
4950
val isWindows = System.getProperty("os.name").startsWith("Windows")
5051
fun launch() = exec {
5152
workingDir = cwd
52-
if (isWindows) commandLine("powershell", "-Command", cmdWin)
53-
else commandLine("sh", "-c", cmdLinux)
53+
val cmd = if (isDownloaded) "./allay" else if (isWindows) cmdWin else cmdLinux
54+
if (isWindows) commandLine("powershell", "-Command", cmd)
55+
else commandLine("sh", "-c", cmd)
5456
}
5557

5658
// https://github.com/gradle/gradle/issues/18716 // kill it manually by click X...

0 commit comments

Comments
 (0)