Skip to content

Commit

Permalink
add WHITE resolver and fix command feedback not always parsing tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jan 27, 2023
1 parent 0e249df commit efe2138
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ object ChattyConfig : IdofrontConfig<ChattyConfig.Data>(chatty, Data.serializer(
@Serializable
data class Chat(
val disableChatSigning: Boolean = true,
val commandSpyFormat: String = "<gold>%chatty_player_displayname%: ",
val commandSpyFormat: String = "<gold><chatty_nickname>: ",
)

@Serializable
data class PrivateMessages(
val enabled: Boolean = true,
val proxy: Boolean = true,
val messageReplyTime: @Serializable(with = DurationSerializer::class) Duration = 5.minutes,
val messageSendFormat: String = "<gold>You -> %%chatty_player_displayname%: ",
val messageReceiveFormat: String = "<gold>%%chatty_player_displayname% -> You: ",
val messageSendFormat: String = "<gold>You -> <chatty_nickname>: ",
val messageReceiveFormat: String = "<gold><chatty_nickname> -> You: ",
val messageSendSound: String = "",
val messageReceivedSound: String = "",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) },
Expand All @@ -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(
Expand All @@ -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())
Expand Down

0 comments on commit efe2138

Please sign in to comment.