From 1ab76723944b1e2e05d506c67d06a62d8b8c2a87 Mon Sep 17 00:00:00 2001 From: srnyx <25808801+srnyx@users.noreply.github.com> Date: Fri, 30 Jun 2023 00:15:36 -0400 Subject: [PATCH] Add Adventure integration --- .../gradlegalaxy/data/AdventureDependency.kt | 43 +++++++++ .../gradlegalaxy/enums/AdventureComponent.kt | 93 +++++++++++++++++++ .../gradlegalaxy/utility/Dependencies.kt | 22 ++++- .../xyz/srnyx/gradlegalaxy/utility/Scripts.kt | 6 +- 4 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/xyz/srnyx/gradlegalaxy/data/AdventureDependency.kt create mode 100644 src/main/kotlin/xyz/srnyx/gradlegalaxy/enums/AdventureComponent.kt diff --git a/src/main/kotlin/xyz/srnyx/gradlegalaxy/data/AdventureDependency.kt b/src/main/kotlin/xyz/srnyx/gradlegalaxy/data/AdventureDependency.kt new file mode 100644 index 0000000..aae9d47 --- /dev/null +++ b/src/main/kotlin/xyz/srnyx/gradlegalaxy/data/AdventureDependency.kt @@ -0,0 +1,43 @@ +package xyz.srnyx.gradlegalaxy.data + +import org.gradle.api.Action +import org.gradle.api.artifacts.ExternalModuleDependency + +import xyz.srnyx.gradlegalaxy.enums.AdventureComponent +import xyz.srnyx.gradlegalaxy.enums.Component + + +/** + * Represents a dependency on a component of Adventure + * + * @param component The component to depend on + * @param version The version of the component to depend on + * @param configuration The configuration to add the dependency to + * @param configurationAction The action to apply to the dependency + */ +data class AdventureDependency(val component: Component, val version: String, val configuration: String? = null, val configurationAction: Action = Action {}) { + companion object { + /** + * Gets the default dependencies for Adventure for Annoying API + * + * @param configuration The configuration to add the dependencies to + * @param apiVersion The version of [AdventureComponent.API] to depend on + * @param textMinimessageVersion The version of [AdventureComponent.Text.MINIMESSAGE] to depend on + * @param textSerializerLegacyVersion The version of [AdventureComponent.Text.Serializer.LEGACY] to depend on + * @param platformBungeecordVersion The version of [AdventureComponent.Platform.BUNGEECORD] to depend on + * + * @return The default dependencies for Adventure for Annoying API + */ + fun getDefaultAnnoying( + configuration: String = "implementation", + apiVersion: String = "4.14.0", + textMinimessageVersion: String = "4.14.0", + textSerializerLegacyVersion: String = "4.14.0", + platformBungeecordVersion: String = "4.3.0", + ): Array = arrayOf( + AdventureDependency(AdventureComponent.API, apiVersion, configuration), + AdventureDependency(AdventureComponent.Text.MINIMESSAGE, textMinimessageVersion, configuration), + AdventureDependency(AdventureComponent.Text.Serializer.LEGACY, textSerializerLegacyVersion, configuration), + AdventureDependency(AdventureComponent.Platform.BUNGEECORD, platformBungeecordVersion, configuration)) + } +} diff --git a/src/main/kotlin/xyz/srnyx/gradlegalaxy/enums/AdventureComponent.kt b/src/main/kotlin/xyz/srnyx/gradlegalaxy/enums/AdventureComponent.kt new file mode 100644 index 0000000..2508a95 --- /dev/null +++ b/src/main/kotlin/xyz/srnyx/gradlegalaxy/enums/AdventureComponent.kt @@ -0,0 +1,93 @@ +package xyz.srnyx.gradlegalaxy.enums + + +/** + * A parent interface for all components + */ +fun interface Component { + /** + * Returns the full component name used for the dependency notation + */ + fun getComponent(): String +} + +/** + * `adventure-` + */ +enum class AdventureComponent : Component { + API, + NBT, + KEY, + BOM, + ANNOTATION_PROCESSORS; + + override fun getComponent(): String = "adventure-" + name.lowercase().replace("_", "-") + + /** + * `adventure-platform-` + */ + enum class Platform : Component { + API, + BUKKIT, + BUNGEECORD, + SPONGEAPI, + FABRIC, + VIAVERSION, + FACET; + + override fun getComponent(): String = "adventure-platform-" + name.lowercase() + } + + /** + * `adventure-extra-` + */ + enum class Extra : Component { + KOTLIN; + + override fun getComponent(): String = "adventure-extra-" + name.lowercase() + } + + /** + * `adventure-text-` + */ + enum class Text : Component { + MINIMESSAGE; + + override fun getComponent(): String = "adventure-text-" + name.lowercase() + + /** + * `adventure-text-serializer-` + */ + enum class Serializer : Component { + LEGACY, + BUNGEECORD, + CONFIGURATE3, + CONFIGURATE4, + JSON, + GSON, + ANSI, + PLAIN; + + override fun getComponent(): String = "adventure-text-serializer-" + name.lowercase() + + /** + * `adventure-text-serializer--impl` + */ + enum class Implementation : Component { + JSON, + GSON; + + override fun getComponent(): String = "adventure-text-serializer-" + name.lowercase() + "-impl" + } + } + + /** + * `adventure-text-logger-` + */ + enum class Logger : Component { + SLF4J; + + override fun getComponent(): String = "adventure-text-logger-" + name.lowercase() + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/xyz/srnyx/gradlegalaxy/utility/Dependencies.kt b/src/main/kotlin/xyz/srnyx/gradlegalaxy/utility/Dependencies.kt index d3db69b..4319ad9 100644 --- a/src/main/kotlin/xyz/srnyx/gradlegalaxy/utility/Dependencies.kt +++ b/src/main/kotlin/xyz/srnyx/gradlegalaxy/utility/Dependencies.kt @@ -11,6 +11,7 @@ import org.gradle.kotlin.dsl.add import org.gradle.kotlin.dsl.exclude import xyz.srnyx.gradlegalaxy.annotations.Ignore +import xyz.srnyx.gradlegalaxy.data.AdventureDependency import xyz.srnyx.gradlegalaxy.enums.PaperVersion import xyz.srnyx.gradlegalaxy.enums.Repository import xyz.srnyx.gradlegalaxy.enums.repository @@ -89,10 +90,25 @@ fun Project.paper( } /** - * 1. Adds the [Repository.JITPACK] repository - * 2. Adds the dependency to the provided Annoying API version + * 1. Adds the [Repository.MAVEN_CENTRAL] repository + * 2. Adds the dependencies to the provided Adventure components + * + * @param dependencies The Adventure dependencies to add + * @param configurationAll The configuration to use for the dependencies if they don't have one specified + */ +fun Project.adventure(vararg dependencies: AdventureDependency, configurationAll: String? = null) { + check(hasJavaPlugin()) { "Java plugin is not applied!" } + repository(Repository.MAVEN_CENTRAL) + dependencies.forEach { addDependencyTo(project.dependencies, it.configuration ?: configurationAll ?: "implementation", "net.kyori:${it.component.getComponent()}:${it.version}", it.configurationAction) } +} + +/** + * 1. Calls [adventure] with the provided [AdventureDependencies][AdventureDependency] if any are provided + * 2. Adds the [Repository.JITPACK] repository + * 3. Adds the dependency to the provided Annoying API version * * @param version The version of Annoying API to use + * @param adventureDependencies The Adventure dependencies to add * @param configuration The configuration to add the dependency to * @param configurationAction The action to apply to the dependency * @@ -100,10 +116,12 @@ fun Project.paper( */ fun Project.annoyingAPI( version: String, + vararg adventureDependencies: AdventureDependency = emptyArray(), configuration: String = "implementation", configurationAction: Action = Action {} ): ExternalModuleDependency { check(hasJavaPlugin()) { "Java plugin is not applied!" } + if (adventureDependencies.isNotEmpty()) adventure(*adventureDependencies) repository(Repository.JITPACK) if (hasShadowPlugin()) relocate("xyz.srnyx.annoyingapi") return addDependencyTo(dependencies, configuration, "xyz.srnyx:annoying-api:$version") { diff --git a/src/main/kotlin/xyz/srnyx/gradlegalaxy/utility/Scripts.kt b/src/main/kotlin/xyz/srnyx/gradlegalaxy/utility/Scripts.kt index 7c84b5a..5498314 100644 --- a/src/main/kotlin/xyz/srnyx/gradlegalaxy/utility/Scripts.kt +++ b/src/main/kotlin/xyz/srnyx/gradlegalaxy/utility/Scripts.kt @@ -17,6 +17,7 @@ import org.gradle.api.tasks.bundling.Jar import org.gradle.kotlin.dsl.* import xyz.srnyx.gradlegalaxy.annotations.Ignore +import xyz.srnyx.gradlegalaxy.data.AdventureDependency import xyz.srnyx.gradlegalaxy.data.pom.DeveloperData import xyz.srnyx.gradlegalaxy.data.pom.LicenseData import xyz.srnyx.gradlegalaxy.data.pom.ScmData @@ -232,6 +233,8 @@ fun Project.setupMC( * @param annoyingAPIVersion The version of Annoying API to use (example: `3.0.1`) * @param group The group of the project (example: `xyz.srnyx`) * @param version The version of the project (example: `1.0.0`) + * @param description The description of the project + * @param adventureDependencies The []Adventure dependencies][AdventureDependency] to add * @param javaVersion The java version of the project (example: [JavaVersion.VERSION_1_8]) * @param replacements The replacements for the [replacements task][addReplacementsTask] * @param textEncoding The text encoding for the [text encoding task][setTextEncoding] @@ -244,6 +247,7 @@ fun Project.setupAnnoyingAPI( group: String = project.group.toString(), version: String = project.version.toString(), description: String? = project.description, + vararg adventureDependencies: AdventureDependency = AdventureDependency.getDefaultAnnoying(), javaVersion: JavaVersion? = null, replacementFiles: Set? = setOf("plugin.yml"), replacements: Map? = getSentinelReplacements(), @@ -254,7 +258,7 @@ fun Project.setupAnnoyingAPI( ): ExternalModuleDependency { check(hasShadowPlugin()) { "Shadow plugin is required for Annoying API!" } setupMC(group, version, description, javaVersion, replacementFiles, replacements, textEncoding, archiveClassifier) - return annoyingAPI(annoyingAPIVersion, configuration, configurationAction) + return annoyingAPI(annoyingAPIVersion, adventureDependencies = adventureDependencies, configuration, configurationAction) } /**