This commit is contained in:
2025-04-29 14:11:15 +08:00
parent 11a1264a4b
commit acbfb6cb27
8 changed files with 56 additions and 29 deletions

View File

@@ -68,10 +68,8 @@ plugins {
```kotlin ```kotlin
runBroker { runBroker {
// This path is the Broker its self bootstrap jar file path, once if run // The download url of the Broker its self bootstrap jar, if you want to use the default, just delete this line
// successful this config is not necessary, because plugin will copy brokerBootstrapDownloadUrl = "C:\\Users\\RTAkl\\Downloads\\afybroker-server-bootstrap-2.4-all.jar"
// this file to `run` dir
brokerBootstrapPath = "C:\\Users\\RTAkl\\Downloads\\afybroker-server-bootstrap-2.4-all.jar"
// the java path, by default plugin will use jdk of project, just delete this line to use the default jdk // the java path, by default plugin will use jdk of project, just delete this line to use the default jdk
javaExecPath = cn.rtast.runbroker.common.JavaExecPath("path/to/java/binary") javaExecPath = cn.rtast.runbroker.common.JavaExecPath("path/to/java/binary")
} }
@@ -81,10 +79,10 @@ runBroker {
```kotlin ```kotlin
runBrokerSubserver { runBrokerSubserver {
// Broker bukkit plugin path // Broker bukkit plugin path, if you want to use the default, just delete this line
brokerBukkitPluginPath = "C:\\Users\\RTAkl\\Downloads\\afybroker-bukkit-2.4-all.jar" brokerBukkitPluginDownloadUrl = "..."
// Broker bungeecord plugin path // Broker bungeecord plugin download url, if you want to use the default, just delete this line
brokerBungeeCordPluginPath = "C:\\Users\\RTAkl\\Downloads\\afybroker-bungee-2.4-all.jar" brokerBungeeCordPluginDownloadUrl = "..."
// minecraft server core path, also all the path configs are one-time // minecraft server core path, also all the path configs are one-time
minecraftServerPath = "E:\\hhwork\\NoobSpigot\\noob-server\\build\\libs\\noob-bundler-1.21.4-R0.1-SNAPSHOT-mojmap.jar" minecraftServerPath = "E:\\hhwork\\NoobSpigot\\noob-server\\build\\libs\\noob-bundler-1.21.4-R0.1-SNAPSHOT-mojmap.jar"
// the subserver count, set to 2 will generate two tasks that can run multiple server instances by default it's 2 // the subserver count, set to 2 will generate two tasks that can run multiple server instances by default it's 2

View File

@@ -1,2 +1,2 @@
kotlin.code.style=official kotlin.code.style=official
pluginVersion=0.1.1 pluginVersion=0.1.2

View File

@@ -0,0 +1,13 @@
/*
* Copyright © 2025 RTAkland
* Date: 2025/4/29 14:03
* Open Source Under Apache-2.0 License
* https://www.apache.org/licenses/LICENSE-2.0
*/
package cn.rtast.runbroker.common.util
import java.net.URI
import java.net.URL
fun String.toURL(): URL = URI(this).toURL()

View File

@@ -13,13 +13,13 @@ import org.gradle.api.tasks.Input
abstract class RunBrokerExtension { abstract class RunBrokerExtension {
@get:Input @get:Input
abstract val brokerBootstrapPath: Property<String> abstract val brokerBootstrapDownloadUrl: Property<String>
@get:Input @get:Input
abstract val javaExecPath: Property<JavaExecPath> abstract val javaExecPath: Property<JavaExecPath>
init { init {
brokerBootstrapPath.convention("./broker.jar") brokerBootstrapDownloadUrl.convention("https://pub-0d3d8f5b51ea4506827ee6da1f0d8c9b.r2.dev/afybroker-server-bootstrap-2.4-all.jar")
javaExecPath.convention(JavaExecPath.DEFAULT) javaExecPath.convention(JavaExecPath.DEFAULT)
} }
} }

View File

@@ -7,12 +7,15 @@
package cn.rtast.runbroker package cn.rtast.runbroker
import cn.rtast.runbroker.common.util.readBytesFromFile import cn.rtast.runbroker.common.util.toURL
import org.gradle.api.DefaultTask import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskAction
import org.slf4j.LoggerFactory
abstract class RunBrokerTask : DefaultTask() { abstract class RunBrokerTask : DefaultTask() {
private val logger = LoggerFactory.getLogger("RunBroker")
init { init {
val shadowJarTask = project.tasks.named("shadowJar").get() val shadowJarTask = project.tasks.named("shadowJar").get()
dependsOn(shadowJarTask) dependsOn(shadowJarTask)
@@ -26,7 +29,9 @@ abstract class RunBrokerTask : DefaultTask() {
val brokerFile = project.layout.projectDirectory val brokerFile = project.layout.projectDirectory
.dir("run/broker/broker.jar").asFile .dir("run/broker/broker.jar").asFile
if (!brokerFile.exists()) { if (!brokerFile.exists()) {
brokerFile.writeBytes(settings.brokerBootstrapPath.get().readBytesFromFile()) logger.info("Downloading broker bootstrap...")
brokerFile.writeBytes(settings.brokerBootstrapDownloadUrl.get().toURL().readBytes())
logger.info("Downloaded...")
} }
val builtJar = shadowJarTask.outputs.files.singleFile val builtJar = shadowJarTask.outputs.files.singleFile
val previousJar = project.layout.projectDirectory val previousJar = project.layout.projectDirectory
@@ -39,6 +44,6 @@ abstract class RunBrokerTask : DefaultTask() {
it.args = listOf("-jar", brokerFile.absolutePath) it.args = listOf("-jar", brokerFile.absolutePath)
it.workingDir = project.layout.projectDirectory.dir("run/broker").asFile it.workingDir = project.layout.projectDirectory.dir("run/broker").asFile
} }
println("Broker started...") logger.info("Broker started...")
} }
} }

View File

@@ -19,10 +19,10 @@ abstract class RunBrokerSubserverExtension {
abstract val subServerCount: Property<Int> abstract val subServerCount: Property<Int>
@get:Input @get:Input
abstract val brokerBukkitPluginPath: Property<String> abstract val brokerBukkitPluginDownloadUrl: Property<String>
@get:Input @get:Input
abstract val brokerBungeeCordPluginPath: Property<String> abstract val brokerBungeeCordPluginDownloadUrl: Property<String>
@get:Input @get:Input
abstract val javaExecPath: Property<JavaExecPath> abstract val javaExecPath: Property<JavaExecPath>
@@ -30,8 +30,8 @@ abstract class RunBrokerSubserverExtension {
init { init {
subServerCount.convention(2) subServerCount.convention(2)
minecraftServerPath.convention("./server.jar") minecraftServerPath.convention("./server.jar")
brokerBukkitPluginPath.convention("./plugin.jar") brokerBukkitPluginDownloadUrl.convention("https://pub-0d3d8f5b51ea4506827ee6da1f0d8c9b.r2.dev/afybroker-bukkit-2.4-all.jar")
brokerBungeeCordPluginPath.convention("./plugin.jar") brokerBungeeCordPluginDownloadUrl.convention("https://pub-0d3d8f5b51ea4506827ee6da1f0d8c9b.r2.dev/afybroker-bungee-2.4-all.jar")
javaExecPath.convention(JavaExecPath.DEFAULT) javaExecPath.convention(JavaExecPath.DEFAULT)
} }
} }

View File

@@ -8,13 +8,17 @@
package cn.rtast.runbroker.subserver.bukkit package cn.rtast.runbroker.subserver.bukkit
import cn.rtast.runbroker.common.util.readBytesFromFile import cn.rtast.runbroker.common.util.readBytesFromFile
import cn.rtast.runbroker.common.util.toURL
import cn.rtast.runbroker.subserver.RunBrokerSubserverExtension import cn.rtast.runbroker.subserver.RunBrokerSubserverExtension
import org.gradle.api.DefaultTask import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskAction
import org.slf4j.LoggerFactory
import java.io.File import java.io.File
abstract class RunBrokerSubServerTask : DefaultTask() { abstract class RunBrokerSubServerTask : DefaultTask() {
private val logger = LoggerFactory.getLogger("RunBrokerSubServer")
init { init {
dependsOn(project.tasks.named("shadowJar")) dependsOn(project.tasks.named("shadowJar"))
} }
@@ -29,9 +33,11 @@ abstract class RunBrokerSubServerTask : DefaultTask() {
val serverCore = File(runDir, "server.jar") val serverCore = File(runDir, "server.jar")
val pluginsDir = File(runDir, "plugins").apply { mkdirs() } val pluginsDir = File(runDir, "plugins").apply { mkdirs() }
val brokerPluginFile = File(pluginsDir, "broker-bukkit.jar") val brokerPluginFile = File(pluginsDir, "broker-bukkit.jar")
if (!brokerPluginFile.exists()) brokerPluginFile.writeBytes( if (!brokerPluginFile.exists()) {
settings.brokerBukkitPluginPath.get().readBytesFromFile() logger.info("Downloading broker bukkit plugin...")
) brokerPluginFile.writeBytes(settings.brokerBukkitPluginDownloadUrl.get().toURL().readBytes())
logger.info("Downloaded...")
}
if (!serverCore.exists()) serverCore.writeBytes(settings.minecraftServerPath.get().readBytesFromFile()) if (!serverCore.exists()) serverCore.writeBytes(settings.minecraftServerPath.get().readBytesFromFile())
val previousPluginJar = File(pluginsDir, "_broker-plugin.jar") val previousPluginJar = File(pluginsDir, "_broker-plugin.jar")
if (previousPluginJar.exists()) previousPluginJar.delete() if (previousPluginJar.exists()) previousPluginJar.delete()
@@ -43,6 +49,6 @@ abstract class RunBrokerSubServerTask : DefaultTask() {
it.workingDir = project.layout.projectDirectory.dir("run/server/$currentTaskName").asFile it.workingDir = project.layout.projectDirectory.dir("run/server/$currentTaskName").asFile
it.args = listOf("-jar", serverCore.absolutePath, "nogui") it.args = listOf("-jar", serverCore.absolutePath, "nogui")
} }
println("Server $currentTaskName started...") logger.info("Server $currentTaskName started...")
} }
} }

View File

@@ -7,10 +7,11 @@
package cn.rtast.runbroker.subserver.bungeecord package cn.rtast.runbroker.subserver.bungeecord
import cn.rtast.runbroker.common.util.readBytesFromFile import cn.rtast.runbroker.common.util.toURL
import cn.rtast.runbroker.subserver.RunBrokerSubserverExtension import cn.rtast.runbroker.subserver.RunBrokerSubserverExtension
import org.gradle.api.DefaultTask import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskAction
import org.slf4j.LoggerFactory
import java.io.File import java.io.File
import java.net.URI import java.net.URI
@@ -19,6 +20,8 @@ private const val BUNGEECORD_DOWNLOAD_URL =
abstract class RunBrokerBungeeCordTask : DefaultTask() { abstract class RunBrokerBungeeCordTask : DefaultTask() {
private val logger = LoggerFactory.getLogger("RunBrokerBungeeCord")
@TaskAction @TaskAction
fun runSubserver() { fun runSubserver() {
val settings = project.extensions.getByType(RunBrokerSubserverExtension::class.java) val settings = project.extensions.getByType(RunBrokerSubserverExtension::class.java)
@@ -26,12 +29,14 @@ abstract class RunBrokerBungeeCordTask : DefaultTask() {
val bungeeCord = File(runDir, "bungee.jar") val bungeeCord = File(runDir, "bungee.jar")
val pluginsDir = File(runDir, "plugins").apply { mkdirs() } val pluginsDir = File(runDir, "plugins").apply { mkdirs() }
val brokerBungeePluginFile = File(pluginsDir, "broker-bungee.jar") val brokerBungeePluginFile = File(pluginsDir, "broker-bungee.jar")
if (!brokerBungeePluginFile.exists()) brokerBungeePluginFile.writeBytes( if (!brokerBungeePluginFile.exists()) {
settings.brokerBungeeCordPluginPath.get().readBytesFromFile() logger.info("Downloading broker BungeeCord plugin...")
) brokerBungeePluginFile.writeBytes(settings.brokerBungeeCordPluginDownloadUrl.get().toURL().readBytes())
println("Downloading Bungeecord...") logger.info("Downloaded...")
}
logger.info("Downloading BungeeCord...")
val bungeeCordBytes = URI(BUNGEECORD_DOWNLOAD_URL).toURL().readBytes() val bungeeCordBytes = URI(BUNGEECORD_DOWNLOAD_URL).toURL().readBytes()
println("BungeeCord downloaded...") logger.info("BungeeCord downloaded...")
if (!bungeeCord.exists()) bungeeCord.writeBytes(bungeeCordBytes) if (!bungeeCord.exists()) bungeeCord.writeBytes(bungeeCordBytes)
val executablePath = settings.javaExecPath.get().path val executablePath = settings.javaExecPath.get().path
project.exec { project.exec {
@@ -39,6 +44,6 @@ abstract class RunBrokerBungeeCordTask : DefaultTask() {
it.workingDir = project.layout.projectDirectory.dir("run/bungee/").asFile it.workingDir = project.layout.projectDirectory.dir("run/bungee/").asFile
it.args = listOf("-jar", bungeeCord.absolutePath) it.args = listOf("-jar", bungeeCord.absolutePath)
} }
println("BungeeCord started...") logger.info("BungeeCord started...")
} }
} }