Skip to content

Commit

Permalink
Add Adventure integration
Browse files Browse the repository at this point in the history
  • Loading branch information
srnyx committed Jun 30, 2023
1 parent 2991871 commit 1ab7672
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 3 deletions.
43 changes: 43 additions & 0 deletions src/main/kotlin/xyz/srnyx/gradlegalaxy/data/AdventureDependency.kt
Original file line number Diff line number Diff line change
@@ -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<ExternalModuleDependency> = 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<AdventureDependency> = 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))
}
}
93 changes: 93 additions & 0 deletions src/main/kotlin/xyz/srnyx/gradlegalaxy/enums/AdventureComponent.kt
Original file line number Diff line number Diff line change
@@ -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-<component>`
*/
enum class AdventureComponent : Component {
API,
NBT,
KEY,
BOM,
ANNOTATION_PROCESSORS;

override fun getComponent(): String = "adventure-" + name.lowercase().replace("_", "-")

/**
* `adventure-platform-<component>`
*/
enum class Platform : Component {
API,
BUKKIT,
BUNGEECORD,
SPONGEAPI,
FABRIC,
VIAVERSION,
FACET;

override fun getComponent(): String = "adventure-platform-" + name.lowercase()
}

/**
* `adventure-extra-<component>`
*/
enum class Extra : Component {
KOTLIN;

override fun getComponent(): String = "adventure-extra-" + name.lowercase()
}

/**
* `adventure-text-<component>`
*/
enum class Text : Component {
MINIMESSAGE;

override fun getComponent(): String = "adventure-text-" + name.lowercase()

/**
* `adventure-text-serializer-<component>`
*/
enum class Serializer : Component {
LEGACY,
BUNGEECORD,
CONFIGURATE3,
CONFIGURATE4,
JSON,
GSON,
ANSI,
PLAIN;

override fun getComponent(): String = "adventure-text-serializer-" + name.lowercase()

/**
* `adventure-text-serializer-<component>-impl`
*/
enum class Implementation : Component {
JSON,
GSON;

override fun getComponent(): String = "adventure-text-serializer-" + name.lowercase() + "-impl"
}
}

/**
* `adventure-text-logger-<component>`
*/
enum class Logger : Component {
SLF4J;

override fun getComponent(): String = "adventure-text-logger-" + name.lowercase()
}
}
}
22 changes: 20 additions & 2 deletions src/main/kotlin/xyz/srnyx/gradlegalaxy/utility/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -89,21 +90,38 @@ 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
*
* @return The [ExternalModuleDependency] of the added Annoying API dependency
*/
fun Project.annoyingAPI(
version: String,
vararg adventureDependencies: AdventureDependency = emptyArray(),
configuration: String = "implementation",
configurationAction: Action<ExternalModuleDependency> = 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") {
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/xyz/srnyx/gradlegalaxy/utility/Scripts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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<String>? = setOf("plugin.yml"),
replacements: Map<String, String>? = getSentinelReplacements(),
Expand All @@ -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)
}

/**
Expand Down

0 comments on commit 1ab7672

Please sign in to comment.