Skip to content

Commit

Permalink
chore: note about messageDeletion not working with disableChatSigning
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Dec 29, 2023
1 parent 863cd91 commit dbdfb21
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import net.kyori.adventure.text.TextReplacementConfig
import net.kyori.adventure.text.event.ClickEvent
import net.kyori.adventure.text.event.HoverEvent
import net.kyori.adventure.text.event.HoverEventSource
import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.format.Style
import net.kyori.adventure.text.format.TextDecoration
import net.kyori.adventure.text.minimessage.MiniMessage
Expand Down Expand Up @@ -218,19 +219,22 @@ fun Component.hoverEventShowText(text: Component) = this.hoverEvent(HoverEventSo

fun formatModerationMessage(messageDeletion: ChattyChannel.MessageDeletion, message: Component, signedMessage: SignedMessage, audience: Audience, source: Player, viewers: Set<Player>): Component {
fun Component.appendDeletionHover(player: Player): Component {
return this.hoverEventShowText(chatty.messages.messageDeletion.hoverText.miniMsg())
.clickEvent(ClickEvent.callback {
val hoverString = Component.empty().hoverEventShowText(message).serialize()
if (!signedMessage.canDelete()) return@callback player.sendFormattedMessage(hoverString + chatty.messages.messageDeletion.deletionFailed)


viewers.forEach {
it.deleteMessage(signedMessage)
if (player != it && it.hasPermission(ChattyPermissions.MODERATION_PERM))
it.sendFormattedMessage(hoverString + chatty.messages.messageDeletion.notifyStaff, optionalPlayer = player)
}
player.sendFormattedMessage(hoverString + chatty.messages.messageDeletion.deletionSuccess)
}).compact()
return when (chatty.config.chat.disableChatSigning) {
true -> this.hoverEventShowText(Component.text("Chat-Signing is disabled, messages cannot be deleted.", NamedTextColor.RED))
false -> this.hoverEventShowText(chatty.messages.messageDeletion.hoverText.miniMsg())
.clickEvent(ClickEvent.callback {
val hoverString = Component.empty().hoverEventShowText(message).serialize()
if (!signedMessage.canDelete()) return@callback player.sendFormattedMessage(hoverString + chatty.messages.messageDeletion.deletionFailed)


viewers.forEach {
it.deleteMessage(signedMessage)
if (player != it && it.hasPermission(ChattyPermissions.MODERATION_PERM))
it.sendFormattedMessage(hoverString + chatty.messages.messageDeletion.notifyStaff, optionalPlayer = player)
}
player.sendFormattedMessage(hoverString + chatty.messages.messageDeletion.deletionSuccess)
}).compact()
}
}

return when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class ChatListener : Listener {
viewers().isEmpty() -> player.sendFormattedMessage(chatty.messages.channels.emptyChannelMessage)
chatty.config.chat.disableChatSigning -> {
playerViewers.forEach { receiver ->
var finalMessage = formatPlayerPingMessage(player, pingedPlayer, receiver, message())
var finalMessage = message()
finalMessage = appendChannelFormat(finalMessage, player, channel)
finalMessage = formatPlayerPingMessage(player, pingedPlayer, receiver, finalMessage)
finalMessage = formatModerationMessage(
channel.messageDeletion,
finalMessage,
Expand All @@ -88,7 +90,6 @@ class ChatListener : Listener {
player,
playerViewers
)
finalMessage = appendChannelFormat(finalMessage, player, channel)

receiver.sendMessage(finalMessage)
}
Expand All @@ -97,7 +98,9 @@ class ChatListener : Listener {
}

else -> renderer { source, _, message, audience ->
var finalMessage = formatPlayerPingMessage(source, pingedPlayer, audience, message)
var finalMessage = message
finalMessage = appendChannelFormat(finalMessage, player, channel)
finalMessage = formatPlayerPingMessage(source, pingedPlayer, audience, finalMessage)
finalMessage = formatModerationMessage(
channel.messageDeletion,
finalMessage,
Expand All @@ -106,7 +109,6 @@ class ChatListener : Listener {
source,
playerViewers
)
finalMessage = appendChannelFormat(finalMessage, player, channel)

return@renderer finalMessage
}
Expand Down

0 comments on commit dbdfb21

Please sign in to comment.