diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt index 4f357ca..58ed208 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt @@ -37,40 +37,39 @@ val getPingEnabledChannels: List = fun String.checkForPlayerPings(channelId: String): Player? { val ping = chatty.config.ping if (channelId !in getPingEnabledChannels || ping.pingPrefix.isEmpty() || ping.pingPrefix !in this) return null - val pingedName = this.substringAfter(ping.pingPrefix).split(" ")[0] + val pingedName = this.substringAfter(ping.pingPrefix).substringBefore(" ") return Bukkit.getOnlinePlayers().firstOrNull { player -> - player.name == pingedName || player.chattyNickname?.let { - MiniMessage.miniMessage().stripTags(it) - } == pingedName + player.name == pingedName || player.chattyNickname?.stripTags() == pingedName } } fun Component.handlePlayerPings(player: Player, pingedPlayer: Player, pingedChannelData: ChannelData) { val ping = chatty.config.ping val pingSound = pingedChannelData.pingSound ?: ping.defaultPingSound - val clickToReply = - if (ping.clickToReply) "Shift + Click to mention!'>" - else "" - val pingMessage = this.replaceText( - TextReplacementConfig.builder() - .match(ping.pingPrefix + pingedPlayer.chattyNickname) - .replacement((ping.pingReceiveFormat + clickToReply + ping.pingPrefix + pingedPlayer.chattyNickname).miniMsg()) - .build() - ) - - if (!pingedChannelData.disablePingSound) - pingedPlayer.playSound(pingedPlayer.location, pingSound, SoundCategory.VOICE, ping.pingVolume, ping.pingPitch) - pingedPlayer.sendMessage(pingMessage) - - val pingerMessage = this.replaceText( - TextReplacementConfig.builder() - .match(ping.pingPrefix + pingedPlayer.chattyNickname) - .replacement((ping.pingSendFormat + ping.pingPrefix + pingedPlayer.chattyNickname).miniMsg()) - .build() - ) - player.sendMessage(pingerMessage) + val pingRegex = "${ping.pingPrefix}(${pingedPlayer.chattyNickname}|${pingedPlayer.name})+".toRegex() + + pingRegex.find(this.serialize())?.let { match -> + + val pingMessage = this.replaceText( + TextReplacementConfig.builder() + .match(match.value) + .replacement((ping.pingReceiveFormat + + ("Shift + Click to mention!'>".takeIf { ping.clickToReply } ?: "") + + match.value).miniMsg()) + .build() + ) + if (!pingedChannelData.disablePingSound) + pingedPlayer.playSound(pingedPlayer.location, pingSound, SoundCategory.VOICE, ping.pingVolume, ping.pingPitch) + pingedPlayer.sendMessage(pingMessage) + + val pingerMessage = this.replaceText( + TextReplacementConfig.builder() + .match(match.value) + .replacement((ping.pingSendFormat + match.value).miniMsg()) + .build() + ) + player.sendMessage(pingerMessage) + } } /** Build a unique instance of MiniMessage with an empty TagResolver and deserializes with a generated one that takes permissions into account diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChatListener.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChatListener.kt index 3564e4d..c0ba677 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChatListener.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/listeners/ChatListener.kt @@ -10,6 +10,7 @@ import com.mineinabyss.geary.datatypes.family.family import com.mineinabyss.geary.papermc.tracking.entities.toGearyOrNull import com.mineinabyss.geary.systems.accessors.Pointer import com.mineinabyss.geary.systems.query.GearyQuery +import com.mineinabyss.idofront.messaging.broadcastVal import com.mineinabyss.idofront.messaging.logError import com.mineinabyss.idofront.messaging.logInfo import com.mineinabyss.idofront.textcomponents.miniMsg