Add Feast, Pit modules and Discord webhook

Introduce two new game modules (FeastManager and PitManager) to handle timed endgame events: announcements, world edits, loot generation, teleportation and escape-prevention logic. Add DiscordWebhookManager to send asynchronous webhook messages (embeds/text) and wire it into SpeedHG and GameManager to broadcast game start/end events. Integrate managers into the game loop and reset lifecycle (startGame), add config entries for Discord, and add corresponding language strings. Also include small tweaks (killer XP reward, minor formatting) and updated resource files.
This commit is contained in:
TDSTOS
2026-03-27 02:15:44 +01:00
parent 72a58fdd9c
commit 07c2963e71
7 changed files with 741 additions and 11 deletions

View File

@@ -0,0 +1,92 @@
package club.mcscrims.speedhg.webhook
import club.mcscrims.speedhg.SpeedHG
import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import kotlin.time.Duration.Companion.seconds
import kotlin.time.toJavaDuration
class DiscordWebhookManager(
private val plugin: SpeedHG
) {
private val enabled: Boolean = plugin.config.getBoolean( "discord.enabled", false )
private val webhookUrl: String? = plugin.config.getString( "discord.webhook-url" )
private val httpClient = HttpClient.newBuilder()
.connectTimeout( 5.seconds.toJavaDuration() )
.build()
private val gson = Gson()
private val scope = CoroutineScope( Dispatchers.IO + SupervisorJob() )
/**
* Sendet eine einfache Textnachricht an den Discord Channel
*/
fun broadcastMessage(
content: String
) {
if ( !enabled || webhookUrl.isNullOrEmpty() )
return
val payload = JsonObject().apply {
addProperty( "content", content )
}
sendPayload( payload )
}
/**
* Sendet ein hübsches Discord-Embed (ideal für Game Start / Game End)
*/
fun broadcastEmbed(
title: String,
description: String,
colorHex: Int = 0x5865F2
) {
if ( !enabled || webhookUrl.isNullOrEmpty() )
return
val embed = JsonObject().apply {
addProperty( "title", title )
addProperty( "description", description )
addProperty( "color", colorHex )
}
val payload = JsonObject().apply {
val embedsArray = JsonArray()
embedsArray.add( embed )
add( "embeds", embedsArray )
}
sendPayload( payload )
}
private fun sendPayload(
payload: JsonObject
) {
scope.launch {
try {
val request = HttpRequest.newBuilder()
.uri(URI.create( webhookUrl!! ))
.header( "Content-Type", "application/json" )
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson( payload )))
.build()
httpClient.send( request, HttpResponse.BodyHandlers.discarding() )
} catch ( e: Exception ) {
plugin.logger.warning( "[Discord] Fehler beim Senden des Webhooks: ${e.message}" )
}
}
}
}