mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-03 21:41:32 +00:00
Add join/quit messages to Bifrost.
This commit is contained in:
@ -5,8 +5,11 @@ import cloud.kubelet.foundation.core.FoundationCorePlugin
|
|||||||
import cloud.kubelet.foundation.core.Util
|
import cloud.kubelet.foundation.core.Util
|
||||||
import com.charleskorn.kaml.Yaml
|
import com.charleskorn.kaml.Yaml
|
||||||
import io.papermc.paper.event.player.AsyncChatEvent
|
import io.papermc.paper.event.player.AsyncChatEvent
|
||||||
|
import net.dv8tion.jda.api.EmbedBuilder
|
||||||
import net.dv8tion.jda.api.JDA
|
import net.dv8tion.jda.api.JDA
|
||||||
import net.dv8tion.jda.api.JDABuilder
|
import net.dv8tion.jda.api.JDABuilder
|
||||||
|
import net.dv8tion.jda.api.MessageBuilder
|
||||||
|
import net.dv8tion.jda.api.entities.TextChannel
|
||||||
import net.dv8tion.jda.api.events.GenericEvent
|
import net.dv8tion.jda.api.events.GenericEvent
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent
|
||||||
import net.dv8tion.jda.api.hooks.EventListener
|
import net.dv8tion.jda.api.hooks.EventListener
|
||||||
@ -14,7 +17,11 @@ import net.kyori.adventure.text.Component
|
|||||||
import net.kyori.adventure.text.TextComponent
|
import net.kyori.adventure.text.TextComponent
|
||||||
import org.bukkit.event.EventHandler
|
import org.bukkit.event.EventHandler
|
||||||
import org.bukkit.event.Listener
|
import org.bukkit.event.Listener
|
||||||
|
import org.bukkit.event.player.PlayerAdvancementDoneEvent
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent
|
||||||
import org.bukkit.plugin.java.JavaPlugin
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
|
import java.awt.Color
|
||||||
import kotlin.io.path.inputStream
|
import kotlin.io.path.inputStream
|
||||||
|
|
||||||
class FoundationBifrostPlugin : JavaPlugin(), EventListener, Listener {
|
class FoundationBifrostPlugin : JavaPlugin(), EventListener, Listener {
|
||||||
@ -50,15 +57,48 @@ class FoundationBifrostPlugin : JavaPlugin(), EventListener, Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
private fun getChannel(): TextChannel? {
|
||||||
private fun onPlayerChat(e: AsyncChatEvent) {
|
|
||||||
val channel = jda.getTextChannelById(config.channel.id)
|
val channel = jda.getTextChannelById(config.channel.id)
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
slF4JLogger.error("Failed to retrieve channel ${config.channel.id}")
|
slF4JLogger.error("Failed to retrieve channel ${config.channel.id}")
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
return channel
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun message(f: MessageBuilder.() -> Unit) = MessageBuilder().apply(f).build()
|
||||||
|
private fun MessageBuilder.embed(f: EmbedBuilder.() -> Unit) {
|
||||||
|
setEmbeds(EmbedBuilder().apply(f).build())
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private fun onPlayerJoin(e: PlayerJoinEvent) {
|
||||||
|
val channel = getChannel() ?: return
|
||||||
|
|
||||||
|
channel.sendMessage(message {
|
||||||
|
embed {
|
||||||
|
setAuthor("${e.player.name} joined the server")
|
||||||
|
setColor(Color.GREEN)
|
||||||
|
}
|
||||||
|
}).queue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private fun onPlayerQuit(e: PlayerQuitEvent) {
|
||||||
|
val channel = getChannel() ?: return
|
||||||
|
|
||||||
|
channel.sendMessage(message {
|
||||||
|
embed {
|
||||||
|
setAuthor("${e.player.name} left the server")
|
||||||
|
setColor(Color.RED)
|
||||||
|
}
|
||||||
|
}).queue()
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
private fun onPlayerChat(e: AsyncChatEvent) {
|
||||||
|
val channel = getChannel() ?: return
|
||||||
val message = e.message()
|
val message = e.message()
|
||||||
|
|
||||||
if (message is TextComponent) {
|
if (message is TextComponent) {
|
||||||
channel.sendMessage("${e.player.name}: ${message.content()}").queue()
|
channel.sendMessage("${e.player.name}: ${message.content()}").queue()
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user