From acbfb6cb273bda1bf1850e1fbe1c7fce44b27186 Mon Sep 17 00:00:00 2001 From: RTAkland Date: Tue, 29 Apr 2025 14:11:15 +0800 Subject: [PATCH] Update --- README.md | 14 ++++++-------- gradle.properties | 2 +- .../cn/rtast/runbroker/common/util/url.kt | 13 +++++++++++++ .../cn/rtast/runbroker/RunBrokerExtension.kt | 4 ++-- .../cn/rtast/runbroker/RunBrokerTask.kt | 11 ++++++++--- .../subserver/RunBrokerSubserverExtension.kt | 8 ++++---- .../bukkit/RunBrokerSubServerTask.kt | 14 ++++++++++---- .../bungeecord/RunBrokerBungeeCordTask.kt | 19 ++++++++++++------- 8 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 runbroker-common/src/main/kotlin/cn/rtast/runbroker/common/util/url.kt diff --git a/README.md b/README.md index 3f7bfdc..5fc3c65 100644 --- a/README.md +++ b/README.md @@ -68,10 +68,8 @@ plugins { ```kotlin runBroker { - // This path is the Broker its self bootstrap jar file path, once if run - // successful this config is not necessary, because plugin will copy - // this file to `run` dir - brokerBootstrapPath = "C:\\Users\\RTAkl\\Downloads\\afybroker-server-bootstrap-2.4-all.jar" + // The download url of the Broker its self bootstrap jar, if you want to use the default, just delete this line + brokerBootstrapDownloadUrl = "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 javaExecPath = cn.rtast.runbroker.common.JavaExecPath("path/to/java/binary") } @@ -81,10 +79,10 @@ runBroker { ```kotlin runBrokerSubserver { - // Broker bukkit plugin path - brokerBukkitPluginPath = "C:\\Users\\RTAkl\\Downloads\\afybroker-bukkit-2.4-all.jar" - // Broker bungeecord plugin path - brokerBungeeCordPluginPath = "C:\\Users\\RTAkl\\Downloads\\afybroker-bungee-2.4-all.jar" + // Broker bukkit plugin path, if you want to use the default, just delete this line + brokerBukkitPluginDownloadUrl = "..." + // Broker bungeecord plugin download url, if you want to use the default, just delete this line + brokerBungeeCordPluginDownloadUrl = "..." // 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" // the subserver count, set to 2 will generate two tasks that can run multiple server instances by default it's 2 diff --git a/gradle.properties b/gradle.properties index 3e50773..50ba0b2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ kotlin.code.style=official -pluginVersion=0.1.1 \ No newline at end of file +pluginVersion=0.1.2 \ No newline at end of file diff --git a/runbroker-common/src/main/kotlin/cn/rtast/runbroker/common/util/url.kt b/runbroker-common/src/main/kotlin/cn/rtast/runbroker/common/util/url.kt new file mode 100644 index 0000000..8e9bebe --- /dev/null +++ b/runbroker-common/src/main/kotlin/cn/rtast/runbroker/common/util/url.kt @@ -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() diff --git a/runbroker-plugin/src/main/kotlin/cn/rtast/runbroker/RunBrokerExtension.kt b/runbroker-plugin/src/main/kotlin/cn/rtast/runbroker/RunBrokerExtension.kt index 34663bb..309a9c4 100644 --- a/runbroker-plugin/src/main/kotlin/cn/rtast/runbroker/RunBrokerExtension.kt +++ b/runbroker-plugin/src/main/kotlin/cn/rtast/runbroker/RunBrokerExtension.kt @@ -13,13 +13,13 @@ import org.gradle.api.tasks.Input abstract class RunBrokerExtension { @get:Input - abstract val brokerBootstrapPath: Property + abstract val brokerBootstrapDownloadUrl: Property @get:Input abstract val javaExecPath: Property init { - brokerBootstrapPath.convention("./broker.jar") + brokerBootstrapDownloadUrl.convention("https://pub-0d3d8f5b51ea4506827ee6da1f0d8c9b.r2.dev/afybroker-server-bootstrap-2.4-all.jar") javaExecPath.convention(JavaExecPath.DEFAULT) } } \ No newline at end of file diff --git a/runbroker-plugin/src/main/kotlin/cn/rtast/runbroker/RunBrokerTask.kt b/runbroker-plugin/src/main/kotlin/cn/rtast/runbroker/RunBrokerTask.kt index 9aade25..3fe61de 100644 --- a/runbroker-plugin/src/main/kotlin/cn/rtast/runbroker/RunBrokerTask.kt +++ b/runbroker-plugin/src/main/kotlin/cn/rtast/runbroker/RunBrokerTask.kt @@ -7,12 +7,15 @@ 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.tasks.TaskAction +import org.slf4j.LoggerFactory abstract class RunBrokerTask : DefaultTask() { + private val logger = LoggerFactory.getLogger("RunBroker") + init { val shadowJarTask = project.tasks.named("shadowJar").get() dependsOn(shadowJarTask) @@ -26,7 +29,9 @@ abstract class RunBrokerTask : DefaultTask() { val brokerFile = project.layout.projectDirectory .dir("run/broker/broker.jar").asFile 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 previousJar = project.layout.projectDirectory @@ -39,6 +44,6 @@ abstract class RunBrokerTask : DefaultTask() { it.args = listOf("-jar", brokerFile.absolutePath) it.workingDir = project.layout.projectDirectory.dir("run/broker").asFile } - println("Broker started...") + logger.info("Broker started...") } } \ No newline at end of file diff --git a/runbroker-subserver-plugin/src/main/kotlin/cn/rtast/runbroker/subserver/RunBrokerSubserverExtension.kt b/runbroker-subserver-plugin/src/main/kotlin/cn/rtast/runbroker/subserver/RunBrokerSubserverExtension.kt index 46525f2..67d5a5e 100644 --- a/runbroker-subserver-plugin/src/main/kotlin/cn/rtast/runbroker/subserver/RunBrokerSubserverExtension.kt +++ b/runbroker-subserver-plugin/src/main/kotlin/cn/rtast/runbroker/subserver/RunBrokerSubserverExtension.kt @@ -19,10 +19,10 @@ abstract class RunBrokerSubserverExtension { abstract val subServerCount: Property @get:Input - abstract val brokerBukkitPluginPath: Property + abstract val brokerBukkitPluginDownloadUrl: Property @get:Input - abstract val brokerBungeeCordPluginPath: Property + abstract val brokerBungeeCordPluginDownloadUrl: Property @get:Input abstract val javaExecPath: Property @@ -30,8 +30,8 @@ abstract class RunBrokerSubserverExtension { init { subServerCount.convention(2) minecraftServerPath.convention("./server.jar") - brokerBukkitPluginPath.convention("./plugin.jar") - brokerBungeeCordPluginPath.convention("./plugin.jar") + brokerBukkitPluginDownloadUrl.convention("https://pub-0d3d8f5b51ea4506827ee6da1f0d8c9b.r2.dev/afybroker-bukkit-2.4-all.jar") + brokerBungeeCordPluginDownloadUrl.convention("https://pub-0d3d8f5b51ea4506827ee6da1f0d8c9b.r2.dev/afybroker-bungee-2.4-all.jar") javaExecPath.convention(JavaExecPath.DEFAULT) } } \ No newline at end of file diff --git a/runbroker-subserver-plugin/src/main/kotlin/cn/rtast/runbroker/subserver/bukkit/RunBrokerSubServerTask.kt b/runbroker-subserver-plugin/src/main/kotlin/cn/rtast/runbroker/subserver/bukkit/RunBrokerSubServerTask.kt index 745b86c..454249c 100644 --- a/runbroker-subserver-plugin/src/main/kotlin/cn/rtast/runbroker/subserver/bukkit/RunBrokerSubServerTask.kt +++ b/runbroker-subserver-plugin/src/main/kotlin/cn/rtast/runbroker/subserver/bukkit/RunBrokerSubServerTask.kt @@ -8,13 +8,17 @@ package cn.rtast.runbroker.subserver.bukkit import cn.rtast.runbroker.common.util.readBytesFromFile +import cn.rtast.runbroker.common.util.toURL import cn.rtast.runbroker.subserver.RunBrokerSubserverExtension import org.gradle.api.DefaultTask import org.gradle.api.tasks.TaskAction +import org.slf4j.LoggerFactory import java.io.File abstract class RunBrokerSubServerTask : DefaultTask() { + private val logger = LoggerFactory.getLogger("RunBrokerSubServer") + init { dependsOn(project.tasks.named("shadowJar")) } @@ -29,9 +33,11 @@ abstract class RunBrokerSubServerTask : DefaultTask() { val serverCore = File(runDir, "server.jar") val pluginsDir = File(runDir, "plugins").apply { mkdirs() } val brokerPluginFile = File(pluginsDir, "broker-bukkit.jar") - if (!brokerPluginFile.exists()) brokerPluginFile.writeBytes( - settings.brokerBukkitPluginPath.get().readBytesFromFile() - ) + if (!brokerPluginFile.exists()) { + 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()) val previousPluginJar = File(pluginsDir, "_broker-plugin.jar") if (previousPluginJar.exists()) previousPluginJar.delete() @@ -43,6 +49,6 @@ abstract class RunBrokerSubServerTask : DefaultTask() { it.workingDir = project.layout.projectDirectory.dir("run/server/$currentTaskName").asFile it.args = listOf("-jar", serverCore.absolutePath, "nogui") } - println("Server $currentTaskName started...") + logger.info("Server $currentTaskName started...") } } \ No newline at end of file diff --git a/runbroker-subserver-plugin/src/main/kotlin/cn/rtast/runbroker/subserver/bungeecord/RunBrokerBungeeCordTask.kt b/runbroker-subserver-plugin/src/main/kotlin/cn/rtast/runbroker/subserver/bungeecord/RunBrokerBungeeCordTask.kt index 9758535..6c2bfac 100644 --- a/runbroker-subserver-plugin/src/main/kotlin/cn/rtast/runbroker/subserver/bungeecord/RunBrokerBungeeCordTask.kt +++ b/runbroker-subserver-plugin/src/main/kotlin/cn/rtast/runbroker/subserver/bungeecord/RunBrokerBungeeCordTask.kt @@ -7,10 +7,11 @@ 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 org.gradle.api.DefaultTask import org.gradle.api.tasks.TaskAction +import org.slf4j.LoggerFactory import java.io.File import java.net.URI @@ -19,6 +20,8 @@ private const val BUNGEECORD_DOWNLOAD_URL = abstract class RunBrokerBungeeCordTask : DefaultTask() { + private val logger = LoggerFactory.getLogger("RunBrokerBungeeCord") + @TaskAction fun runSubserver() { val settings = project.extensions.getByType(RunBrokerSubserverExtension::class.java) @@ -26,12 +29,14 @@ abstract class RunBrokerBungeeCordTask : DefaultTask() { val bungeeCord = File(runDir, "bungee.jar") val pluginsDir = File(runDir, "plugins").apply { mkdirs() } val brokerBungeePluginFile = File(pluginsDir, "broker-bungee.jar") - if (!brokerBungeePluginFile.exists()) brokerBungeePluginFile.writeBytes( - settings.brokerBungeeCordPluginPath.get().readBytesFromFile() - ) - println("Downloading Bungeecord...") + if (!brokerBungeePluginFile.exists()) { + logger.info("Downloading broker BungeeCord plugin...") + brokerBungeePluginFile.writeBytes(settings.brokerBungeeCordPluginDownloadUrl.get().toURL().readBytes()) + logger.info("Downloaded...") + } + logger.info("Downloading BungeeCord...") val bungeeCordBytes = URI(BUNGEECORD_DOWNLOAD_URL).toURL().readBytes() - println("BungeeCord downloaded...") + logger.info("BungeeCord downloaded...") if (!bungeeCord.exists()) bungeeCord.writeBytes(bungeeCordBytes) val executablePath = settings.javaExecPath.get().path project.exec { @@ -39,6 +44,6 @@ abstract class RunBrokerBungeeCordTask : DefaultTask() { it.workingDir = project.layout.projectDirectory.dir("run/bungee/").asFile it.args = listOf("-jar", bungeeCord.absolutePath) } - println("BungeeCord started...") + logger.info("BungeeCord started...") } } \ No newline at end of file