-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from Crazy-Crew/dev
A few plugin enhancements here & there.
- Loading branch information
Showing
65 changed files
with
1,641 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
.gradle | ||
.idea | ||
|
||
build | ||
build | ||
|
||
build-logic/.gradle | ||
build-logic/build | ||
|
||
core/build | ||
|
||
platforms/paper/build | ||
platforms/paper/run/* | ||
|
||
!platforms/paper/run/eula.txt | ||
!platforms/paper/run/bukkit.yml | ||
!platforms/paper/run/spigot.yml | ||
!platforms/paper/run/server.properties | ||
!platforms/paper/run/config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
implementation(tools.jetbrains) | ||
implementation(tools.license) | ||
implementation(tools.shadowJar) | ||
|
||
// For the webhook tasks, this applies to the build-logic only | ||
implementation(tools.ktor.gson) | ||
implementation(tools.ktor.core) | ||
implementation(tools.ktor.cio) | ||
implementation(tools.ktor.cn) | ||
implementation(tools.kotlinx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@file:Suppress("UnstableApiUsage") | ||
|
||
dependencyResolutionManagement { | ||
versionCatalogs { | ||
create("tools") { | ||
from(files("../gradle/tools.versions.toml")) | ||
} | ||
} | ||
|
||
repositories.gradlePluginPortal() | ||
} |
28 changes: 28 additions & 0 deletions
28
build-logic/src/main/kotlin/crazyenvoys.base-plugin.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
plugins { | ||
`java-library` | ||
|
||
`maven-publish` | ||
|
||
id("com.github.hierynomus.license") | ||
|
||
id("com.github.johnrengelman.shadow") | ||
} | ||
|
||
license { | ||
header = rootProject.file("LICENSE") | ||
encoding = "UTF-8" | ||
|
||
mapping("java", "JAVADOC_STYLE") | ||
|
||
include("**/*.java") | ||
} | ||
|
||
java { | ||
toolchain.languageVersion.set(JavaLanguageVersion.of(project.properties["java_version"].toString())) | ||
} | ||
|
||
tasks { | ||
compileJava { | ||
options.release.set(project.properties["java_version"].toString().toInt()) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
build-logic/src/main/kotlin/crazyenvoys.paper-plugin.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
id("crazyenvoys.root-plugin") | ||
} | ||
|
||
repositories { | ||
maven("https://repo.papermc.io/repository/maven-public/") | ||
|
||
/** | ||
* NBT API | ||
*/ | ||
maven("https://repo.codemc.io/repository/maven-public/") | ||
} |
28 changes: 28 additions & 0 deletions
28
build-logic/src/main/kotlin/crazyenvoys.root-plugin.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import task.ReleaseWebhook | ||
import task.WebhookExtension | ||
|
||
plugins { | ||
id("crazyenvoys.base-plugin") | ||
} | ||
|
||
repositories { | ||
maven("https://repo.triumphteam.dev/snapshots/") | ||
|
||
maven("https://repo.crazycrew.us/plugins/") | ||
|
||
maven("https://libraries.minecraft.net/") | ||
|
||
maven("https://jitpack.io/") | ||
|
||
mavenCentral() | ||
} | ||
|
||
tasks { | ||
// Creating the extension to be available on the root gradle | ||
val webhookExtension = extensions.create("webhook", WebhookExtension::class) | ||
|
||
// Register the task | ||
register<ReleaseWebhook>("webhook") { | ||
extension = webhookExtension | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package task | ||
|
||
import io.ktor.client.HttpClient | ||
import io.ktor.client.engine.cio.CIO | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.client.request.headers | ||
import io.ktor.client.request.post | ||
import io.ktor.client.request.setBody | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.http.append | ||
import io.ktor.serialization.gson.gson | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.runBlocking | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
/** Task to send webhooks to discord. */ | ||
abstract class ReleaseWebhook : DefaultTask() { | ||
|
||
/** Configured extension. */ | ||
@get:Input | ||
lateinit var extension: WebhookExtension | ||
|
||
/** Ktor client for easy requests. */ | ||
private val client = HttpClient(CIO) { | ||
install(ContentNegotiation) { | ||
gson() | ||
} | ||
} | ||
|
||
@TaskAction | ||
fun webhook() { | ||
// The webhook url configured in the gradle.properties | ||
val url = System.getenv("DISCORD_WEBHOOK") | ||
|
||
runBlocking(Dispatchers.IO) { | ||
val response = client.post(url) { | ||
headers { | ||
append(HttpHeaders.ContentType, ContentType.Application.Json) | ||
} | ||
|
||
setBody(extension.build()) | ||
} | ||
|
||
// Should be using logger, but eh | ||
println("Webhook result: ${response.status}") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
package task | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import java.awt.Color | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
/** Extension to simplify customizing the webhook. */ | ||
abstract class WebhookExtension { | ||
|
||
private var content: String = "" | ||
private var username: String = "" | ||
private var avatar: String = "" | ||
private val embeds: MutableList<Embed> = mutableListOf() | ||
|
||
fun content(content: String) { | ||
this.content = content; | ||
} | ||
|
||
fun username(username: String) { | ||
this.username = username; | ||
} | ||
|
||
fun avatar(avatar: String) { | ||
this.avatar = avatar; | ||
} | ||
|
||
fun embeds(builder: EmbedsBuilder.() -> Unit) { | ||
embeds.addAll(EmbedsBuilder().apply(builder).build()) | ||
} | ||
|
||
internal fun build(): Webhook { | ||
return Webhook( | ||
content, | ||
username, | ||
avatar, | ||
false, | ||
embeds.toList() | ||
) | ||
} | ||
|
||
class EmbedsBuilder { | ||
private val embeds: MutableList<Embed> = mutableListOf() | ||
|
||
fun embed(builder: EmbedBuilder.() -> Unit) { | ||
embeds.add(EmbedBuilder().apply(builder).build()) | ||
} | ||
|
||
internal fun build() = embeds.toList() | ||
} | ||
|
||
class EmbedBuilder { | ||
private var title: String? = null | ||
private var description: String? = null | ||
private var url: String? = null | ||
private var timestamp: String = "" | ||
private var color: Int? = null | ||
private var footer: Footer? = null | ||
private var image: Image? = null | ||
private var thumbnail: Image? = null | ||
private var provider: Provider? = null | ||
private var author: Author? = null | ||
private var fields: List<Field>? = null | ||
|
||
fun title(title: String) { | ||
this.title = title | ||
} | ||
|
||
fun description(description: String) { | ||
this.description = description | ||
} | ||
|
||
fun url(url: String) { | ||
this.url = url | ||
} | ||
|
||
fun timestamp(date: LocalDateTime) { | ||
this.timestamp = date.format(DateTimeFormatter.ISO_DATE_TIME) | ||
} | ||
|
||
fun color(color: Color) { | ||
this.color = color.toInt() | ||
} | ||
|
||
fun footer(text: String, icon: String? = null) { | ||
this.footer = Footer(text, icon) | ||
} | ||
|
||
fun image(url: String) { | ||
this.image = Image(url) | ||
} | ||
|
||
fun thumbnail(url: String) { | ||
this.thumbnail = Image(url) | ||
} | ||
|
||
fun provider(name: String? = null, url: String? = null) { | ||
this.provider = Provider(name, url) | ||
} | ||
|
||
fun author(name: String, url: String? = null, icon: String? = null) { | ||
this.author = Author(name, url, icon) | ||
} | ||
|
||
fun fields(builder: FieldsBuilder.() -> Unit) { | ||
this.fields = FieldsBuilder().apply(builder).build() | ||
} | ||
|
||
internal fun build() = Embed( | ||
title, | ||
description, | ||
url, | ||
timestamp, | ||
color, | ||
footer, | ||
image, | ||
thumbnail, | ||
provider, | ||
author, | ||
fields, | ||
) | ||
} | ||
|
||
class FieldsBuilder { | ||
private val fields: MutableList<Field> = mutableListOf() | ||
|
||
fun field(name: String, value: String, inline: Boolean = false) { | ||
fields.add(Field(name, value, inline)) | ||
} | ||
|
||
internal fun build() = fields.toList() | ||
} | ||
|
||
data class Webhook( | ||
val content: String, | ||
val username: String, | ||
@SerializedName("avatar_url") val avatarUrl: String, | ||
val tts: Boolean, | ||
val embeds: List<Embed>, | ||
) | ||
|
||
data class Embed( | ||
val title: String?, | ||
val description: String?, | ||
val url: String?, | ||
val timestamp: String, | ||
val color: Int?, | ||
val footer: Footer?, | ||
val image: Image?, | ||
val thumbnail: Image?, | ||
val provider: Provider?, | ||
val author: Author?, | ||
val fields: List<Field>?, | ||
) | ||
|
||
data class Image( | ||
val url: String, | ||
) | ||
|
||
data class Author( | ||
val name: String, | ||
val url: String?, | ||
@SerializedName("icon_url") val iconUrl: String?, | ||
) | ||
|
||
data class Provider( | ||
val name: String?, | ||
val url: String?, | ||
) | ||
|
||
data class Footer( | ||
val text: String, | ||
@SerializedName("icon_url") val iconUrl: String?, | ||
) | ||
|
||
data class Field( | ||
val name: String, | ||
val value: String, | ||
val inline: Boolean?, | ||
) | ||
} | ||
|
||
/** Turns color into integer for webhook, using this because [Color]'s rgb method returns negatives. */ | ||
private fun Color.toInt(): Int { | ||
val red = red shl 16 and 0xFF0000 | ||
val green = green shl 8 and 0x00FF00 | ||
val blue = blue and 0x0000FF | ||
|
||
return red or green or blue | ||
} |
Oops, something went wrong.