Add toggles for start, shutdown, player join and quit events.

This commit is contained in:
Logan Gorence 2021-12-23 03:44:07 +00:00
parent 4439fe74a6
commit b8c8097f58
No known key found for this signature in database
GPG Key ID: 9743CEF10935949A
3 changed files with 21 additions and 3 deletions

View File

@ -63,9 +63,7 @@ class FoundationBifrostPlugin : JavaPlugin(), EventListener, Listener {
override fun onEvent(e: GenericEvent) {
when (e) {
is ReadyEvent -> {
val channel = getChannel() ?: return
if (isDev) return
channel.sendMessage(":white_check_mark: Server is ready!").queue()
onDiscordReady()
}
is MessageReceivedEvent -> {
// Prevent this bot from receiving its own messages and creating a feedback loop.
@ -97,6 +95,7 @@ class FoundationBifrostPlugin : JavaPlugin(), EventListener, Listener {
@EventHandler
private fun onPlayerJoin(e: PlayerJoinEvent) {
if (!config.channel.sendPlayerJoin) return
val channel = getChannel() ?: return
channel.sendMessage(message {
@ -109,6 +108,7 @@ class FoundationBifrostPlugin : JavaPlugin(), EventListener, Listener {
@EventHandler
private fun onPlayerQuit(e: PlayerQuitEvent) {
if (!config.channel.sendPlayerQuit) return
val channel = getChannel() ?: return
channel.sendMessage(message {
@ -131,7 +131,15 @@ class FoundationBifrostPlugin : JavaPlugin(), EventListener, Listener {
}
}
private fun onDiscordReady() {
if (!config.channel.sendStart) return
val channel = getChannel() ?: return
if (isDev) return
channel.sendMessage(":white_check_mark: Server is ready!").queue()
}
private fun onServerStop() {
if (!config.channel.sendShutdown) return
val channel = getChannel() ?: return
if (isDev) return
channel.sendMessage(":octagonal_sign: Server is stopping!").queue()

View File

@ -16,4 +16,8 @@ data class BifrostAuthentication(
@Serializable
data class BifrostChannel(
val id: String,
val sendStart: Boolean = true,
val sendShutdown: Boolean = true,
val sendPlayerJoin: Boolean = true,
val sendPlayerQuit: Boolean = true,
)

View File

@ -8,3 +8,9 @@ channel:
# Channel ID, can be copied by turning on Developer Mode in User Settings -> Advanced. The ID can
# then be copied by right-clicking the channel and selecting "Copy ID".
id: 123456789
# Toggles for common events that generate notifications that are sent to the channel.
sendStart: true
sendShutdown: true
sendPlayerJoin: true
sendPlayerQuit: true