Skip to content

Commit

Permalink
tweaks to tagresolver builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jan 26, 2023
1 parent 36c7a1d commit eea6e5c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,21 @@ fun Component.handlePlayerPings(player: Player, pingedPlayer: Player) {
* @param ignorePermissions Whether to ignore permissions and parse all tags
*/
fun String.parseTags(player: Player? = null, ignorePermissions: Boolean = false): Component {
val tagResolver = TagResolver.builder()
//TODO Figure out why this doesn't respect denied standard perms?
return MiniMessage.miniMessage().deserialize(this.fixSerializedTags(), player.buildTagResolver(ignorePermissions))
}

// custom tags
tagResolver.resolver(player.chattyPlaceholderTags)
//tagResolver.resolver(ChattyTags.RESOLVER)
fun Player?.buildTagResolver(ignorePermissions: Boolean = false): TagResolver {
val tagResolver = TagResolver.builder()

if (ignorePermissions || player == null || player.hasPermission(ChattyPermissions.BYPASS_TAG_PERM))
if (ignorePermissions || this?.hasPermission(ChattyPermissions.BYPASS_TAG_PERM) != false) {
// custom tags
tagResolver.resolver(chattyPlaceholderTags)
tagResolver.resolvers(ChattyPermissions.chatFormattingPerms.values)
else ChattyPermissions.chatFormattingPerms.forEach { (perm, tag) ->
if (player.hasPermission(perm))
tagResolver.resolver(tag)
}
else tagResolver.resolvers(ChattyPermissions.chatFormattingPerms.filter { hasPermission(it.key) }.map { it.value })

return MiniMessage.miniMessage().deserialize(this.fixSerializedTags(), tagResolver.build())
return tagResolver.build()
}

fun Component.parseTags(player: Player? = null, ignorePermissions: Boolean = false) =
Expand Down Expand Up @@ -212,7 +213,7 @@ fun formattedResult(player: Player, message: Component): Component {
player.verifyPlayerChannel()
val channel = player.getChannelFromPlayer() ?: return message
val parsedFormat = translatePlaceholders(player, channel.format).parseTags(player, true)
val parsedMessage = message.parseTags(player).color(channel.messageColor)
val parsedMessage = message.parseTags(player, false).color(channel.messageColor)

return parsedFormat.append(parsedMessage)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ChatListener : Listener {

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
fun AsyncChatCommandDecorateEvent.onCommandPreview() {
player()?.let { result(originalMessage().parseTags(it)) }
player()?.let { result(originalMessage().parseTags(it, false)) }
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
Expand Down Expand Up @@ -122,7 +122,7 @@ class ChatListener : Listener {

private fun Component.stripMessageFormat(player: Player, channel: ChattyConfig.Data.ChattyChannel) =
plainText.serialize(this)
.replace(plainText.serialize(translatePlaceholders(player, channel.format).parseTags(player)), "").miniMsg()
.replace(plainText.serialize(translatePlaceholders(player, channel.format).parseTags(player, true)), "").miniMsg().parseTags(player, false)
}

object RendererExtension : ChatRenderer {
Expand Down
4 changes: 2 additions & 2 deletions chatty-paper/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ channels:
isDefaultChannel: false
discordsrv: false
logToConsole: true
format: ":survival:%chatty_shift_-8%:local: <yellow><chatty_nickname><yellow>: "
format: ":survival:<shift:-8>:local: <yellow><chatty_nickname><yellow>: "
messageColor: "yellow"
channelRadius: 500
channelAliases:
Expand All @@ -123,7 +123,7 @@ channels:
discordsrv: false
proxy: true
logToConsole: false
format: ":survival:%chatty_shift_-8%:admin:<chatty_nickname><red>: "
format: ":survival:<shift:-8>:admin:<red><chatty_nickname><red>: "
messageColor: "red"
channelAliases:
- "a"

0 comments on commit eea6e5c

Please sign in to comment.