From 5b63b7973082c781a9501256374f54e714601edf Mon Sep 17 00:00:00 2001 From: "Piotr W." Date: Sat, 25 Apr 2026 16:00:09 +0100 Subject: [PATCH] improve build system to use dynamic plugin.yml generation --- build.gradle.kts | 52 ++++++++++++------- gradle.properties | 4 ++ .../szlaban/command/CommandManager.java | 6 +-- src/main/resources/plugin.yml | 28 ---------- 4 files changed, 40 insertions(+), 50 deletions(-) delete mode 100644 src/main/resources/plugin.yml diff --git a/build.gradle.kts b/build.gradle.kts index c45ddac..02c0785 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,4 @@ +import net.minecrell.pluginyml.bukkit.BukkitPluginDescription import xyz.jpenilla.runpaper.task.RunServer plugins { @@ -6,6 +7,7 @@ plugins { id("xyz.jpenilla.run-paper") version "3.0.2" id("com.gradleup.shadow") version "9.4.1" id("io.papermc.paperweight.userdev") version "2.0.0-beta.21" + id("de.eldoria.plugin-yml.bukkit") version "0.9.0" } group = project.property("group") as String @@ -39,8 +41,9 @@ dependencies { testRuntimeOnly("org.junit.platform:junit-platform-launcher") // mocking framework testImplementation("org.mockito:mockito-core:5.+") - // libraries for tests - // testImplementation("io.papermc.paper:paper-api:${targetMcVersion}-R0.1-SNAPSHOT") + + // bukkit + bukkitLibrary("com.google.code.gson", "gson", "2.10.1") } tasks { @@ -108,23 +111,34 @@ tasks.withType().configureEach { } } -tasks.processResources { -// dynamic for the plugin.json - val props = mapOf( - "version" to version, - "name" to project.property("name") as String, - "description" to project.property("description") as String, - "website" to project.property("website") as String, - "authors" to (project.property("authors") as String).trim('[', ']').split(","), - "contributors" to (project.property("contributors") as String).trim('[', ']').split(","), - "main" to project.property("main") as String, - "prefix" to project.property("prefix") as String, - "api_version" to targetMcVersion, - ) - inputs.properties(props) - filteringCharset = "UTF-8" +bukkit { + main = project.property("main") as String + load = BukkitPluginDescription.PluginLoadOrder.STARTUP; + apiVersion = project.property("target") as String + prefix = project.property("prefix") as String + foliaSupported = false - filesMatching("plugin.yml") { - expand(props) + description = project.property("description") as String + website = project.property("website") as String + authors = (project.property("authors") as String).trim('[', ']').split(",").map { it.trim() } + contributors = (project.property("contributors") as String).trim('[', ']').split(",").map { it.trim() }.filter { it.isNotEmpty() } + + depend = (project.property("depend") as String).trim('[', ']').split(",").map { it.trim() }.filter { it.isNotEmpty() } + softDepend = (project.property("softDepend") as String).trim('[', ']').split(",").map { it.trim() }.filter { it.isNotEmpty() } + + permissions { + register("szlaban.*") { + description = "Grants all Szlaban permissions" + default = BukkitPluginDescription.Permission.Default.OP + children = listOf("szlaban.admin", "szlaban.use") + } + register("szlaban.admin") { + description = "Grants admin permissions" + default = BukkitPluginDescription.Permission.Default.OP + } + register("szlaban.advisor") { + description = "Allows full use of the Advisor module" + default = BukkitPluginDescription.Permission.Default.OP + } } } diff --git a/gradle.properties b/gradle.properties index cb91570..c9bd41f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,3 +17,7 @@ prefix = Szlaban # target mc version, must be >= 1.17 # won't compile below 1.20.6 target = 1.21.1 + +# dependencies +depend = [ ] +softDepend = [ ProtocolLib ] diff --git a/src/main/java/dev/piotr_weychan/szlaban/command/CommandManager.java b/src/main/java/dev/piotr_weychan/szlaban/command/CommandManager.java index f2e4ba0..8308b1e 100644 --- a/src/main/java/dev/piotr_weychan/szlaban/command/CommandManager.java +++ b/src/main/java/dev/piotr_weychan/szlaban/command/CommandManager.java @@ -77,7 +77,7 @@ public class CommandManager { private LiteralCommandNode module() { return Commands.literal("module") - .requires(ctx -> ctx.getSender().hasPermission("szlaban.config")) + .requires(ctx -> ctx.getSender().hasPermission("szlaban.admin")) .then(Commands.argument("module", StringArgumentType.string()) .suggests((ctx, builder) -> { for (String module : moduleManager.getModuleIds()) { @@ -146,7 +146,7 @@ public class CommandManager { private LiteralCommandNode modules() { return Commands.literal("modules") - .requires(ctx -> ctx.getSender().hasPermission("szlaban.config")) + .requires(ctx -> ctx.getSender().hasPermission("szlaban.admin")) .executes(ctx -> { List modules = moduleManager.getModuleIds().stream().map(id -> { Module module = moduleManager.getModule(id); @@ -181,7 +181,7 @@ public class CommandManager { private LiteralCommandNode reloadConfig() { return Commands.literal("reload") - .requires(ctx -> ctx.getSender().hasPermission("szlaban.config")) + .requires(ctx -> ctx.getSender().hasPermission("szlaban.admin")) .executes(ctx -> { plugin.reloadConfig(); moduleManager.getModuleIds().forEach(moduleManager::reloadModule); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml deleted file mode 100644 index ee26846..0000000 --- a/src/main/resources/plugin.yml +++ /dev/null @@ -1,28 +0,0 @@ -# DO NOT EDIT! -# This file is dynamically populated by Gradle on build from gradle.properties -# If you want to change any values, change them there! Otherwise this file may -# become broken! -# The only parts you should touch are depend and libraries if the project gains -# new dependencies. - -# Plugin Metadata -name: ${name} -version: ${version} -prefix: ${prefix} -description: ${description} -website: ${website} - -# Authorship -authors: ${authors} -contributors: ${contributors} - -# Permissions and Commands -# ... - -# Development and Plugin Loading -api-version: ${api_version} -main: ${main} -depend: [] -softdepend: - - ProtocolLib -libraries: [] \ No newline at end of file