From efe2138d68bfea7e4816302f49c8f71d50a22760 Mon Sep 17 00:00:00 2001 From: Boy Date: Fri, 27 Jan 2023 17:13:39 +0100 Subject: [PATCH] add WHITE resolver and fix command feedback not always parsing tags --- .../src/main/kotlin/com/mineinabyss/chatty/ChattyConfig.kt | 6 +++--- .../kotlin/com/mineinabyss/chatty/helpers/ChatHelpers.kt | 2 ++ .../kotlin/com/mineinabyss/chatty/listeners/ChatListener.kt | 2 +- .../main/kotlin/com/mineinabyss/chatty/tags/ChattyTags.kt | 6 ++++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyConfig.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyConfig.kt index 265ff6c..7f84a85 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyConfig.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/ChattyConfig.kt @@ -28,7 +28,7 @@ object ChattyConfig : IdofrontConfig(chatty, Data.serializer( @Serializable data class Chat( val disableChatSigning: Boolean = true, - val commandSpyFormat: String = "%chatty_player_displayname%: ", + val commandSpyFormat: String = ": ", ) @Serializable @@ -36,8 +36,8 @@ object ChattyConfig : IdofrontConfig(chatty, Data.serializer( val enabled: Boolean = true, val proxy: Boolean = true, val messageReplyTime: @Serializable(with = DurationSerializer::class) Duration = 5.minutes, - val messageSendFormat: String = "You -> %%chatty_player_displayname%: ", - val messageReceiveFormat: String = "%%chatty_player_displayname% -> You: ", + val messageSendFormat: String = "You -> : ", + val messageReceiveFormat: String = " -> You: ", val messageSendSound: String = "", val messageReceivedSound: String = "", ) 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 fb149be..faccda2 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 @@ -7,6 +7,7 @@ import com.mineinabyss.chatty.components.ChannelType import com.mineinabyss.chatty.components.chattyData import com.mineinabyss.chatty.components.chattyNickname import com.mineinabyss.chatty.placeholders.chattyPlaceholderTags +import com.mineinabyss.chatty.tags.ChattyTags.WHITE_RESOLVER import com.mineinabyss.idofront.messaging.miniMsg import com.mineinabyss.idofront.messaging.serialize import me.clip.placeholderapi.PlaceholderAPI @@ -87,6 +88,7 @@ fun Player?.buildTagResolver(ignorePermissions: Boolean = false): TagResolver { } else tagResolver.resolvers(ChattyPermissions.chatFormattingPerms.filter { hasPermission(it.key) }.map { it.value }) + tagResolver.resolvers(WHITE_RESOLVER) return tagResolver.build() } 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 d9ba1e8..99d4f40 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 @@ -118,7 +118,7 @@ class ChatListener : Listener { } private fun Player.sendFormattedMessage(vararg message: String, optionalPlayer: Player? = null) = - this.sendMessage(translatePlaceholders((optionalPlayer ?: this), message.joinToString(" "))) + this.sendMessage(translatePlaceholders((optionalPlayer ?: this), message.joinToString(" ")).parseTags(optionalPlayer ?: this, true)) private fun Component.stripMessageFormat(player: Player, channel: ChattyConfig.Data.ChattyChannel) = plainText.serialize(this) diff --git a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/tags/ChattyTags.kt b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/tags/ChattyTags.kt index 07b8b72..ba03b9c 100644 --- a/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/tags/ChattyTags.kt +++ b/chatty-paper/src/main/kotlin/com/mineinabyss/chatty/tags/ChattyTags.kt @@ -5,6 +5,7 @@ import com.mineinabyss.chatty.helpers.translatePlayerHeadComponent import com.mineinabyss.idofront.font.Space import com.mineinabyss.idofront.messaging.miniMsg import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.NamedTextColor import net.kyori.adventure.text.minimessage.Context import net.kyori.adventure.text.minimessage.internal.serializer.SerializableResolver import net.kyori.adventure.text.minimessage.tag.Tag @@ -15,6 +16,7 @@ object ChattyTags { private val SHIFT = "shift" private val HEAD = "head" + private val WHITE = "white" val SHIFT_RESOLVER: TagResolver = SerializableResolver.claimingComponent( SHIFT, { args: ArgumentQueue, ctx: Context -> create(args, ctx, SHIFT) }, @@ -25,6 +27,9 @@ object ChattyTags { { component: Component? -> emit(component) } ) + val WHITE_RESOLVER: TagResolver = SerializableResolver.claimingComponent(WHITE, { args: ArgumentQueue, ctx: Context -> create(args, ctx, WHITE) }, + { component: Component? -> emit(component) }) + private fun create(args: ArgumentQueue, ctx: Context, tag: String): Tag { when (tag) { SHIFT -> return if (args.hasNext()) Tag.selfClosingInserting( @@ -35,6 +40,7 @@ object ChattyTags { args.popOr("A player name is needed").value().toPlayer()?.translatePlayerHeadComponent() ?: Component.empty() ) else Tag.selfClosingInserting(Component.empty()) + WHITE -> Tag.selfClosingInserting(Component.empty().color(NamedTextColor.WHITE)) } return Tag.inserting(Component.empty())