improve build system to use dynamic plugin.yml generation

This commit is contained in:
Piotr W. committed 2026-04-25 16:00:09 +01:00
1 parent 9a81bca0cc
commit 5b63b79730
4 files changed
+40 -50

No files matched your search

+33 -19
View File
@@ -1,3 +1,4 @@
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
import xyz.jpenilla.runpaper.task.RunServer import xyz.jpenilla.runpaper.task.RunServer
plugins { plugins {
@@ -6,6 +7,7 @@ plugins {
id("xyz.jpenilla.run-paper") version "3.0.2" id("xyz.jpenilla.run-paper") version "3.0.2"
id("com.gradleup.shadow") version "9.4.1" id("com.gradleup.shadow") version "9.4.1"
id("io.papermc.paperweight.userdev") version "2.0.0-beta.21" 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 group = project.property("group") as String
@@ -39,8 +41,9 @@ dependencies {
testRuntimeOnly("org.junit.platform:junit-platform-launcher") testRuntimeOnly("org.junit.platform:junit-platform-launcher")
// mocking framework // mocking framework
testImplementation("org.mockito:mockito-core:5.+") 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 { tasks {
@@ -108,23 +111,34 @@ tasks.withType<JavaCompile>().configureEach {
} }
} }
tasks.processResources { bukkit {
// dynamic for the plugin.json main = project.property("main") as String
val props = mapOf( load = BukkitPluginDescription.PluginLoadOrder.STARTUP;
"version" to version, apiVersion = project.property("target") as String
"name" to project.property("name") as String, prefix = project.property("prefix") as String
"description" to project.property("description") as String, foliaSupported = false
"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"
filesMatching("plugin.yml") { description = project.property("description") as String
expand(props) 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
}
} }
} }
+4
View File
@@ -17,3 +17,7 @@ prefix = Szlaban
# target mc version, must be >= 1.17 # target mc version, must be >= 1.17
# won't compile below 1.20.6 # won't compile below 1.20.6
target = 1.21.1 target = 1.21.1
# dependencies
depend = [ ]
softDepend = [ ProtocolLib ]
@@ -77,7 +77,7 @@ public class CommandManager {
private LiteralCommandNode<CommandSourceStack> module() { private LiteralCommandNode<CommandSourceStack> module() {
return Commands.literal("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()) .then(Commands.argument("module", StringArgumentType.string())
.suggests((ctx, builder) -> { .suggests((ctx, builder) -> {
for (String module : moduleManager.getModuleIds()) { for (String module : moduleManager.getModuleIds()) {
@@ -146,7 +146,7 @@ public class CommandManager {
private LiteralCommandNode<CommandSourceStack> modules() { private LiteralCommandNode<CommandSourceStack> modules() {
return Commands.literal("modules") return Commands.literal("modules")
.requires(ctx -> ctx.getSender().hasPermission("szlaban.config")) .requires(ctx -> ctx.getSender().hasPermission("szlaban.admin"))
.executes(ctx -> { .executes(ctx -> {
List<Component> modules = moduleManager.getModuleIds().stream().map(id -> { List<Component> modules = moduleManager.getModuleIds().stream().map(id -> {
Module module = moduleManager.getModule(id); Module module = moduleManager.getModule(id);
@@ -181,7 +181,7 @@ public class CommandManager {
private LiteralCommandNode<CommandSourceStack> reloadConfig() { private LiteralCommandNode<CommandSourceStack> reloadConfig() {
return Commands.literal("reload") return Commands.literal("reload")
.requires(ctx -> ctx.getSender().hasPermission("szlaban.config")) .requires(ctx -> ctx.getSender().hasPermission("szlaban.admin"))
.executes(ctx -> { .executes(ctx -> {
plugin.reloadConfig(); plugin.reloadConfig();
moduleManager.getModuleIds().forEach(moduleManager::reloadModule); moduleManager.getModuleIds().forEach(moduleManager::reloadModule);
-28
View File
@@ -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: []