From cd518c6928af512eb0f0378f6cf4cb6ec38f0457 Mon Sep 17 00:00:00 2001 From: Kenneth Endfinger Date: Sat, 15 Jan 2022 23:24:35 -0500 Subject: [PATCH] Bifrost: Add simple player death notifications. --- .../bifrost/FoundationBifrostPlugin.kt | 25 +++++++++++++++---- .../foundation/bifrost/model/BifrostConfig.kt | 1 + 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/foundation-bifrost/src/main/kotlin/cloud/kubelet/foundation/bifrost/FoundationBifrostPlugin.kt b/foundation-bifrost/src/main/kotlin/cloud/kubelet/foundation/bifrost/FoundationBifrostPlugin.kt index 98a5a67..675bb66 100644 --- a/foundation-bifrost/src/main/kotlin/cloud/kubelet/foundation/bifrost/FoundationBifrostPlugin.kt +++ b/foundation-bifrost/src/main/kotlin/cloud/kubelet/foundation/bifrost/FoundationBifrostPlugin.kt @@ -13,16 +13,18 @@ import net.dv8tion.jda.api.entities.TextChannel import net.dv8tion.jda.api.events.GenericEvent import net.dv8tion.jda.api.events.ReadyEvent import net.dv8tion.jda.api.events.message.MessageReceivedEvent -import net.dv8tion.jda.api.hooks.EventListener as DiscordEventListener import net.kyori.adventure.text.Component import net.kyori.adventure.text.TextComponent import org.bukkit.event.EventHandler -import org.bukkit.event.Listener as BukkitEventListener +import org.bukkit.event.EventPriority +import org.bukkit.event.entity.PlayerDeathEvent import org.bukkit.event.player.PlayerJoinEvent import org.bukkit.event.player.PlayerQuitEvent import org.bukkit.plugin.java.JavaPlugin import java.awt.Color import kotlin.io.path.inputStream +import net.dv8tion.jda.api.hooks.EventListener as DiscordEventListener +import org.bukkit.event.Listener as BukkitEventListener class FoundationBifrostPlugin : JavaPlugin(), DiscordEventListener, BukkitEventListener { private lateinit var config: BifrostConfig @@ -102,7 +104,7 @@ class FoundationBifrostPlugin : JavaPlugin(), DiscordEventListener, BukkitEventL setEmbeds(EmbedBuilder().apply(f).build()) } - @EventHandler + @EventHandler(priority = EventPriority.MONITOR) private fun onPlayerJoin(e: PlayerJoinEvent) { if (!config.channel.sendPlayerJoin) return val channel = getChannel() ?: return @@ -115,7 +117,7 @@ class FoundationBifrostPlugin : JavaPlugin(), DiscordEventListener, BukkitEventL }).queue() } - @EventHandler + @EventHandler(priority = EventPriority.MONITOR) private fun onPlayerQuit(e: PlayerQuitEvent) { if (!config.channel.sendPlayerQuit) return val channel = getChannel() ?: return @@ -128,7 +130,7 @@ class FoundationBifrostPlugin : JavaPlugin(), DiscordEventListener, BukkitEventL }).queue() } - @EventHandler + @EventHandler(priority = EventPriority.MONITOR) private fun onPlayerChat(e: AsyncChatEvent) { if (!config.channel.bridge) return val channel = getChannel() ?: return @@ -141,6 +143,19 @@ class FoundationBifrostPlugin : JavaPlugin(), DiscordEventListener, BukkitEventL } } + @EventHandler(priority = EventPriority.MONITOR) + private fun onPlayerDeath(e: PlayerDeathEvent) { + if (!config.channel.sendPlayerDeath) return + val channel = getChannel() ?: return + + channel.sendMessage(message { + embed { + setAuthor("${e.player.name} died") + setColor(Color.RED) + } + }).queue() + } + private fun onDiscordReady() { if (!config.channel.sendStart) return val channel = getChannel() ?: return diff --git a/foundation-bifrost/src/main/kotlin/cloud/kubelet/foundation/bifrost/model/BifrostConfig.kt b/foundation-bifrost/src/main/kotlin/cloud/kubelet/foundation/bifrost/model/BifrostConfig.kt index 35abfec..de5ab66 100644 --- a/foundation-bifrost/src/main/kotlin/cloud/kubelet/foundation/bifrost/model/BifrostConfig.kt +++ b/foundation-bifrost/src/main/kotlin/cloud/kubelet/foundation/bifrost/model/BifrostConfig.kt @@ -21,4 +21,5 @@ data class BifrostChannel( val sendShutdown: Boolean = true, val sendPlayerJoin: Boolean = true, val sendPlayerQuit: Boolean = true, + val sendPlayerDeath: Boolean = true )