Skip to content

Commit

Permalink
fix: usage of raw unicodes from default font not being handled by per…
Browse files Browse the repository at this point in the history
…mission
  • Loading branch information
Boy0000 committed Dec 11, 2023
1 parent 0552951 commit 845a443
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/src/main/kotlin/com/mineinabyss/emojy/EmojyHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ private fun Component.replaceEmoteIds(player: Player, insert: Boolean = true): C
var msg = GlobalTranslator.render(this, player.locale())
val serialized = msg.serialize()

// Replace all unicodes found in default font with a random one
// This is to prevent use of unicodes from the font the chat is in
for (emote in emojy.emotes.filter { it.font == Key.key("default") }) emote.unicodes().forEach {
val replacement =
if (emote.checkPermission(player)) emote.formattedUnicode(insert = insert, colorable = false, bitmapIndex = 0)
else "\\:${emote.id}:".miniMsg()
msg = msg.replaceText(
TextReplacementConfig.builder()
.matchLiteral(it)
.replacement(replacement)
.build()
)
}

for (emote in emojy.emotes) emote.baseRegex.findAll(serialized).forEach { match ->
val colorable = colorableRegex in match.value
val bitmapIndex = bitmapIndexRegex.find(match.value)?.groupValues?.get(1)?.toIntOrNull() ?: -1
Expand Down

0 comments on commit 845a443

Please sign in to comment.