mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Add helper for enabling/disabling third party plugins in run tasks (#343)
This commit is contained in:
1 parent
48cb5d9a29
commit
b63d998b21
7 files changed
+100
-11
No files matched your search
@@ -83,3 +83,5 @@ gradle-app.setting
|
||||
|
||||
**/run/
|
||||
**/run2/
|
||||
|
||||
**/run-plugins.yml
|
||||
@@ -15,6 +15,7 @@ dependencies {
|
||||
implementation(libs.minotaur)
|
||||
implementation(libs.configurateYaml)
|
||||
implementation(libs.gremlin.gradle)
|
||||
implementation(libs.run.task)
|
||||
|
||||
implementation(libs.pluginYml)
|
||||
// Implementation dependencies of plugin-yml
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import org.gradle.api.Action
|
||||
import org.gradle.api.artifacts.ExternalModuleDependency
|
||||
import org.gradle.api.artifacts.MinimalExternalModuleDependency
|
||||
import org.gradle.api.provider.ListProperty
|
||||
import org.gradle.api.provider.Provider
|
||||
|
||||
abstract class ConfigurablePluginsExt {
|
||||
data class DepPlugin(
|
||||
val dep: Provider<MinimalExternalModuleDependency>,
|
||||
val op: Action<in ExternalModuleDependency>?,
|
||||
val defaultEnabled: Boolean = false,
|
||||
val name: String = dep.get().name
|
||||
)
|
||||
|
||||
abstract val gradleDependencyBased: ListProperty<DepPlugin>
|
||||
|
||||
fun dependency(lib: Provider<MinimalExternalModuleDependency>, op: Action<in ExternalModuleDependency>? = null) {
|
||||
gradleDependencyBased.add(DepPlugin(lib, op))
|
||||
}
|
||||
|
||||
fun dependency(lib: Provider<MinimalExternalModuleDependency>, defaultEnabled: Boolean, op: Action<in ExternalModuleDependency>? = null) {
|
||||
gradleDependencyBased.add(DepPlugin(lib, op, defaultEnabled))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable
|
||||
import org.spongepowered.configurate.yaml.NodeStyle
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader
|
||||
import xyz.jpenilla.runtask.task.RunWithPlugins
|
||||
|
||||
val ext = extensions.create("configurablePlugins", ConfigurablePluginsExt::class.java)
|
||||
|
||||
afterEvaluate {
|
||||
ext.gradleDependencyBased.get().forEach { entry ->
|
||||
val c = configurations.register(entry.name + "Plugin") {
|
||||
isTransitive = false
|
||||
}
|
||||
dependencies {
|
||||
c.name(entry.dep) { entry.op?.execute(this) }
|
||||
}
|
||||
tasks.withType(RunWithPlugins::class).configureEach {
|
||||
val cfg = readConfig()
|
||||
val enabled = cfg.taskOverrides[name]?.get(entry.name)
|
||||
?: cfg.defaults[entry.name]
|
||||
?: false
|
||||
if (enabled) {
|
||||
pluginJars.from(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ConfigSerializable
|
||||
class Config {
|
||||
var defaults: MutableMap<String, Boolean> = mutableMapOf()
|
||||
var taskOverrides: MutableMap<String, MutableMap<String, Boolean>> = mutableMapOf(
|
||||
"someTaskName" to mutableMapOf("somePlugin" to false)
|
||||
)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun readConfig(): Config {
|
||||
val loader = YamlConfigurationLoader.builder()
|
||||
.file(file("run-plugins.yml"))
|
||||
.nodeStyle(NodeStyle.BLOCK)
|
||||
.defaultOptions {
|
||||
it.header("""
|
||||
Enable and disable optional plugins for run tasks in this project
|
||||
""".trimIndent())
|
||||
}
|
||||
.build()
|
||||
val n = loader.load()
|
||||
val c = n.get(Config::class.java) as Config
|
||||
var write = false
|
||||
for (e in ext.gradleDependencyBased.get()) {
|
||||
if (!c.defaults.containsKey(e.name)) {
|
||||
write = true
|
||||
c.defaults[e.name] = e.defaultEnabled
|
||||
}
|
||||
}
|
||||
if (write) {
|
||||
n.set(c)
|
||||
loader.save(n)
|
||||
}
|
||||
return c
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
[plugins]
|
||||
sponge-gradle = { id = "org.spongepowered.gradle.plugin", version = "2.2.0" }
|
||||
runPaper = { id = "xyz.jpenilla.run-paper", version.ref = "runTask" }
|
||||
runVelocity = { id = "xyz.jpenilla.run-velocity", version.ref = "runTask" }
|
||||
hangar-publish = { id = "io.papermc.hangar-publish-plugin", version = "0.1.0" }
|
||||
indra-publishing-sonatype = { id = "net.kyori.indra.publishing.sonatype", version.ref = "indra" }
|
||||
|
||||
@@ -40,7 +38,7 @@ adventurePlatformFabric = "5.10.0"
|
||||
luckPermsApi = "5.4"
|
||||
essentialsx = "2.19.3"
|
||||
discordsrv = "1.26.0"
|
||||
placeholderapi = "2.10.9"
|
||||
placeholderapi = "2.11.5"
|
||||
miniplaceholders = "2.2.2"
|
||||
jdbi = "3.41.3"
|
||||
hikari = "5.1.0"
|
||||
@@ -57,7 +55,7 @@ postgresql = "42.6.0"
|
||||
rabbitmq = "5.20.0"
|
||||
nats = "2.16.14"
|
||||
h2 = "2.2.224"
|
||||
towny = "0.100.0.0"
|
||||
towny = "0.100.0.2"
|
||||
|
||||
[libraries]
|
||||
indraCommon = { group = "net.kyori", name = "indra-common", version.ref = "indra" }
|
||||
@@ -66,6 +64,7 @@ shadow = { group = "com.github.johnrengelman", name = "shadow", version.ref = "s
|
||||
pluginYml = { group = "net.minecrell", name = "plugin-yml", version.ref = "pluginYml" }
|
||||
minotaur = { group = "com.modrinth.minotaur", name = "Minotaur", version.ref = "minotaur" }
|
||||
gremlin-gradle = { group = "xyz.jpenilla", name = "gremlin-gradle", version.ref = "gremlin" }
|
||||
run-task = { module = "xyz.jpenilla:run-task", version.ref = "runTask" }
|
||||
|
||||
adventureBom = { group = "net.kyori", name = "adventure-bom", version.ref = "adventure" }
|
||||
adventureApi = { group = "net.kyori", name = "adventure-api" }
|
||||
|
||||
@@ -4,8 +4,9 @@ plugins {
|
||||
id("carbon.shadow-platform")
|
||||
id("net.minecrell.plugin-yml.bukkit")
|
||||
id("paper-plugin-yml")
|
||||
alias(libs.plugins.runPaper)
|
||||
id("xyz.jpenilla.run-paper")
|
||||
id("carbon.permissions")
|
||||
id("carbon.configurable-plugins")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -33,6 +34,8 @@ dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
configurablePlugins.dependency(libs.towny)
|
||||
|
||||
tasks {
|
||||
shadowJar {
|
||||
relocateDependency("io.papermc.papertrail")
|
||||
@@ -42,18 +45,16 @@ tasks {
|
||||
withType(RunServer::class).configureEach {
|
||||
version.set(libs.versions.minecraft)
|
||||
downloadPlugins {
|
||||
url("https://download.luckperms.net/1515/bukkit/loader/LuckPerms-Bukkit-5.4.102.jar")
|
||||
url("https://download.luckperms.net/1521/bukkit/loader/LuckPerms-Bukkit-5.4.108.jar")
|
||||
github("MiniPlaceholders", "MiniPlaceholders", libs.versions.miniplaceholders.get(), "MiniPlaceholders-Paper-${libs.versions.miniplaceholders.get()}.jar")
|
||||
github("MiniPlaceholders", "PlaceholderAPI-Expansion", "1.2.0", "PlaceholderAPI-Expansion-1.2.0.jar")
|
||||
hangar("PlaceholderAPI", "2.11.5")
|
||||
hangar("PlaceholderAPI", libs.versions.placeholderapi.get())
|
||||
}
|
||||
}
|
||||
register<RunServer>("runServer2") {
|
||||
pluginJars.from(shadowJar.flatMap { it.archiveFile })
|
||||
runDirectory.set(layout.projectDirectory.dir("run2"))
|
||||
}
|
||||
writeDependencies {
|
||||
}
|
||||
}
|
||||
|
||||
runPaper.folia.registerTask()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
plugins {
|
||||
id("carbon.shadow-platform")
|
||||
alias(libs.plugins.runVelocity)
|
||||
id("xyz.jpenilla.run-velocity")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -34,7 +34,8 @@ tasks {
|
||||
runVelocity {
|
||||
velocityVersion(libs.versions.velocityApi.get())
|
||||
downloadPlugins {
|
||||
url("https://download.luckperms.net/1515/velocity/LuckPerms-Velocity-5.4.102.jar")
|
||||
url("https://download.luckperms.net/1521/velocity/LuckPerms-Velocity-5.4.108.jar")
|
||||
github("MiniPlaceholders", "MiniPlaceholders", libs.versions.miniplaceholders.get(), "MiniPlaceholders-Velocity-${libs.versions.miniplaceholders.get()}.jar")
|
||||
}
|
||||
}
|
||||
processResources {
|
||||
|
||||
Reference in new issue
Block a user