@@ -34,27 +34,21 @@ tasks.shadowJar {
3434 archiveClassifier = " shaded"
3535}
3636
37- tasks.register<Copy >(" runServer" ) {
37+ tasks.register<JavaExec >(" runServer" ) {
3838 outputs.upToDateWhen { false }
3939 dependsOn(" shadowJar" )
40- val launcherRepo = " https://raw.githubusercontent.com/AllayMC/AllayLauncher/refs/heads/main/scripts"
41- val cmdWin = " Invoke-Expression (Invoke-WebRequest -Uri \" ${launcherRepo} /install_windows.ps1\" ).Content"
42- val cmdLinux = " wget -qO- ${launcherRepo} /install_linux.sh | bash"
43- val cwd = layout.buildDirectory.file(" run" ).get().asFile
4440
4541 val shadowJar = tasks.named(" shadowJar" , ShadowJar ::class ).get()
46- from(shadowJar.archiveFile.get().asFile)
47- into(cwd.resolve(" plugins" ).apply { mkdirs() })
48-
49- val isDownloaded = cwd.listFiles()!! .any { it.isFile && it.nameWithoutExtension == " allay" }
50- val isWindows = System .getProperty(" os.name" ).startsWith(" Windows" )
51- fun launch () = exec {
52- workingDir = cwd
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)
56- }
57-
58- // https://github.com/gradle/gradle/issues/18716 // kill it manually by click X...
59- doLast { launch() }
42+ val pluginJar = shadowJar.archiveFile.get().asFile
43+ val cwd = layout.buildDirectory.file(" run" ).get().asFile
44+ val pluginsDir = cwd.resolve(" plugins" ).apply { mkdirs() }
45+ doFirst { pluginJar.copyTo(File (pluginsDir, pluginJar.name), overwrite = true ) }
46+
47+ val group = " org.allaymc.allay"
48+ val allays = configurations.compileOnly.get().dependencies.filter { it.group == group }
49+ val dependency = allays.find { it.name == " server" } ? : allays.find { it.name == " api" }!!
50+ val server = dependencies.create(" $group :server:${dependency.version} " )
51+ classpath = files(configurations.detachedConfiguration(server).resolve())
52+ mainClass = " org.allaymc.server.Allay"
53+ workingDir = cwd
6054}
0 commit comments