mirror of
				https://github.com/GayPizzaSpecifications/foundation.git
				synced 2025-11-04 11:39:39 +00:00 
			
		
		
		
	Gradle: Implement --update option for setupPaperServer, and add runPaperServer
This commit is contained in:
		@ -135,7 +135,7 @@ subprojects {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tasks.setupPaperServer {
 | 
					foundation {
 | 
				
			||||||
  minecraftServerPath = "server"
 | 
					  minecraftServerPath.set("server")
 | 
				
			||||||
  paperVersionGroup = "1.18"
 | 
					  paperVersionGroup.set("1.18")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					package cloud.kubelet.foundation.gradle
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.gradle.api.provider.Property
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					interface FoundationExtension {
 | 
				
			||||||
 | 
					  val paperVersionGroup: Property<String>
 | 
				
			||||||
 | 
					  val minecraftServerPath: Property<String>
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -2,9 +2,13 @@ package cloud.kubelet.foundation.gradle
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import org.gradle.api.Plugin
 | 
					import org.gradle.api.Plugin
 | 
				
			||||||
import org.gradle.api.Project
 | 
					import org.gradle.api.Project
 | 
				
			||||||
 | 
					import org.gradle.kotlin.dsl.create
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class FoundationGradlePlugin : Plugin<Project> {
 | 
					class FoundationGradlePlugin : Plugin<Project> {
 | 
				
			||||||
  override fun apply(project: Project) {
 | 
					  override fun apply(project: Project) {
 | 
				
			||||||
    project.tasks.create("setupPaperServer", SetupPaperServer::class.java)
 | 
					    project.extensions.create<FoundationExtension>("foundation")
 | 
				
			||||||
 | 
					    val setupPaperServer = project.tasks.create<SetupPaperServer>("setupPaperServer")
 | 
				
			||||||
 | 
					    val runPaperServer = project.tasks.create<RunPaperServer>("runPaperServer")
 | 
				
			||||||
 | 
					    runPaperServer.dependsOn(setupPaperServer)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					package cloud.kubelet.foundation.gradle
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.gradle.api.DefaultTask
 | 
				
			||||||
 | 
					import org.gradle.api.tasks.TaskAction
 | 
				
			||||||
 | 
					import org.gradle.kotlin.dsl.getByType
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					open class RunPaperServer : DefaultTask() {
 | 
				
			||||||
 | 
					  init {
 | 
				
			||||||
 | 
					    outputs.upToDateWhen { false }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @TaskAction
 | 
				
			||||||
 | 
					  fun runPaperServer() {
 | 
				
			||||||
 | 
					    val foundation = project.extensions.getByType<FoundationExtension>()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    val minecraftServerDirectory = project.file(foundation.minecraftServerPath.get())
 | 
				
			||||||
 | 
					    val paperJarFile = minecraftServerDirectory.resolve("paper.jar")
 | 
				
			||||||
 | 
					    project.javaexec {
 | 
				
			||||||
 | 
					      classpath(paperJarFile.absolutePath)
 | 
				
			||||||
 | 
					      workingDir(minecraftServerDirectory)
 | 
				
			||||||
 | 
					      args("nogui")
 | 
				
			||||||
 | 
					      mainClass.set("io.papermc.paperclip.Main")
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -3,34 +3,35 @@ package cloud.kubelet.foundation.gradle
 | 
				
			|||||||
import org.gradle.api.DefaultTask
 | 
					import org.gradle.api.DefaultTask
 | 
				
			||||||
import org.gradle.api.tasks.Input
 | 
					import org.gradle.api.tasks.Input
 | 
				
			||||||
import org.gradle.api.tasks.TaskAction
 | 
					import org.gradle.api.tasks.TaskAction
 | 
				
			||||||
 | 
					import org.gradle.api.tasks.options.Option
 | 
				
			||||||
 | 
					import org.gradle.kotlin.dsl.getByType
 | 
				
			||||||
 | 
					import java.io.File
 | 
				
			||||||
import java.nio.file.Files
 | 
					import java.nio.file.Files
 | 
				
			||||||
 | 
					
 | 
				
			||||||
open class SetupPaperServer : DefaultTask() {
 | 
					open class SetupPaperServer : DefaultTask() {
 | 
				
			||||||
  @get:Input
 | 
					  init {
 | 
				
			||||||
  lateinit var paperVersionGroup: String
 | 
					    outputs.upToDateWhen { false }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @get:Input
 | 
					  @get:Input
 | 
				
			||||||
  lateinit var minecraftServerPath: String
 | 
					  @set:Option(option = "update", description = "Update Paper Server")
 | 
				
			||||||
 | 
					  var shouldUpdatePaperServer = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private val paperVersionClient = PaperVersionClient()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @TaskAction
 | 
					  @TaskAction
 | 
				
			||||||
  fun downloadPaperTask() {
 | 
					  fun downloadPaperTask() {
 | 
				
			||||||
    val minecraftServerDirectory = project.file(minecraftServerPath)
 | 
					    val foundation = project.extensions.getByType<FoundationExtension>()
 | 
				
			||||||
    val client = PaperVersionClient()
 | 
					    val minecraftServerDirectory = project.file(foundation.minecraftServerPath.get())
 | 
				
			||||||
    val builds = client.getVersionBuilds(paperVersionGroup)
 | 
					 | 
				
			||||||
    val build = builds.last()
 | 
					 | 
				
			||||||
    val download = build.downloads["application"]!!
 | 
					 | 
				
			||||||
    val url = client.resolveDownloadUrl(build, download)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!minecraftServerDirectory.exists()) {
 | 
					    if (!minecraftServerDirectory.exists()) {
 | 
				
			||||||
      minecraftServerDirectory.mkdirs()
 | 
					      minecraftServerDirectory.mkdirs()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ant.invokeMethod(
 | 
					    val paperJarFile = project.file("${foundation.minecraftServerPath.get()}/paper.jar")
 | 
				
			||||||
      "get", mapOf(
 | 
					    if (!paperJarFile.exists() || shouldUpdatePaperServer) {
 | 
				
			||||||
        "src" to url.toString(),
 | 
					      downloadLatestBuild(foundation.paperVersionGroup.get(), paperJarFile)
 | 
				
			||||||
        "dest" to project.file("${minecraftServerPath}/paper.jar").absolutePath
 | 
					    }
 | 
				
			||||||
      )
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    val paperPluginsDirectory = minecraftServerDirectory.resolve("plugins")
 | 
					    val paperPluginsDirectory = minecraftServerDirectory.resolve("plugins")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -52,4 +53,20 @@ open class SetupPaperServer : DefaultTask() {
 | 
				
			|||||||
      Files.createSymbolicLink(pluginLinkFile.toPath(), pluginJarFile.toPath())
 | 
					      Files.createSymbolicLink(pluginLinkFile.toPath(), pluginJarFile.toPath())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private fun downloadLatestBuild(paperVersionGroup: String, paperJarFile: File) {
 | 
				
			||||||
 | 
					    val builds = paperVersionClient.getVersionBuilds(paperVersionGroup)
 | 
				
			||||||
 | 
					    val build = builds.last()
 | 
				
			||||||
 | 
					    val download = build.downloads["application"]!!
 | 
				
			||||||
 | 
					    val url = paperVersionClient.resolveDownloadUrl(build, download)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ant.invokeMethod(
 | 
				
			||||||
 | 
					      "get", mapOf(
 | 
				
			||||||
 | 
					        "src" to url.toString(),
 | 
				
			||||||
 | 
					        "dest" to paperJarFile.absolutePath
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    logger.lifecycle("Installed Paper Server ${build.version} build ${build.build}")
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user