Skip to content

Commit

Permalink
fix: finally fix dumbass escape bs tomfuckery
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Dec 11, 2023
1 parent 783451d commit 136bbf5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 13 additions & 11 deletions core/src/main/kotlin/com/mineinabyss/emojy/EmojyHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.mineinabyss.emojy
import com.mineinabyss.emojy.config.SPACE_PERMISSION
import com.mineinabyss.idofront.font.Space
import com.mineinabyss.idofront.messaging.logInfo
import com.mineinabyss.idofront.messaging.logSuccess
import com.mineinabyss.idofront.textcomponents.miniMsg
import com.mineinabyss.idofront.textcomponents.serialize
import net.kyori.adventure.key.Key
Expand All @@ -24,8 +25,6 @@ private fun Component.replaceEmoteIds(player: Player, insert: Boolean = true): C
var msg = GlobalTranslator.render(this, player.locale())
val serialized = msg.serialize()

logInfo("replace: $serialized")

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 All @@ -34,7 +33,7 @@ private fun Component.replaceEmoteIds(player: Player, insert: Boolean = true): C
else "\\${match.value}".miniMsg()
msg = msg.replaceText(
TextReplacementConfig.builder()
.matchLiteral(match.value)
.match(emote.baseRegex.pattern)
.replacement(replacement)
.build()
)
Expand All @@ -45,7 +44,7 @@ private fun Component.replaceEmoteIds(player: Player, insert: Boolean = true): C
else "\\:${gif.id}:".miniMsg()
msg = msg.replaceText(
TextReplacementConfig.builder()
.matchLiteral(match.value)
.match(gif.baseRegex.pattern)
.replacement(replacement)
.build()
)
Expand All @@ -57,7 +56,7 @@ private fun Component.replaceEmoteIds(player: Player, insert: Boolean = true): C

msg = msg.replaceText(
TextReplacementConfig.builder()
.matchLiteral(match.value)
.match(spaceRegex.pattern)
.replacement(replacement)
.build()
)
Expand All @@ -75,14 +74,17 @@ private fun Component.transformEmoteIds(insert: Boolean = true): Component {
var msg = this
val serialized = this.serialize()

if (!serialized.contains("transform") && !serialized.contains("happyhud")) logSuccess(serialized)

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

msg = msg.replaceText(
TextReplacementConfig.builder()
.matchLiteral(match.value)
.match(emote.baseRegex.pattern)
.replacement(emote.formattedUnicode(insert = insert, colorable = colorable, bitmapIndex = bitmapIndex))
.build()
)
Expand All @@ -91,7 +93,7 @@ private fun Component.transformEmoteIds(insert: Boolean = true): Component {
emote.escapedRegex.findAll(serialized).forEach { match ->
msg = msg.replaceText(
TextReplacementConfig.builder()
.matchLiteral(match.value)
.match(emote.escapedRegex.pattern)
.replacement(match.value.removePrefix("\\"))
.build()
)
Expand All @@ -102,7 +104,7 @@ private fun Component.transformEmoteIds(insert: Boolean = true): Component {
gif.baseRegex.findAll(serialized).forEach { match ->
msg = msg.replaceText(
TextReplacementConfig.builder()
.matchLiteral(match.value)
.match(gif.baseRegex.pattern)
.replacement(gif.formattedUnicode(insert = insert))
.build()
)
Expand All @@ -111,7 +113,7 @@ private fun Component.transformEmoteIds(insert: Boolean = true): Component {
gif.escapedRegex.findAll(serialized).forEach { match ->
msg = msg.replaceText(
TextReplacementConfig.builder()
.matchLiteral(match.value)
.match(gif.escapedRegex.pattern)
.replacement(match.value.removePrefix("\\"))
.build()
)
Expand All @@ -122,7 +124,7 @@ private fun Component.transformEmoteIds(insert: Boolean = true): Component {
val space = match.groupValues[1].toIntOrNull() ?: return@forEach
msg = msg.replaceText(
TextReplacementConfig.builder()
.matchLiteral(match.value)
.match(spaceRegex.pattern)
.replacement(buildSpaceComponents(space))
.build()
)
Expand All @@ -131,7 +133,7 @@ private fun Component.transformEmoteIds(insert: Boolean = true): Component {
escapedSpaceRegex.findAll(serialized).forEach { match ->
msg = msg.replaceText(
TextReplacementConfig.builder()
.matchLiteral(match.value)
.match(escapedSpaceRegex.pattern)
.replacement(match.value.removePrefix("\\"))
.build()
)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=com.mineinabyss
version=0.6
version=0.7
idofrontVersion=0.20.13

0 comments on commit 136bbf5

Please sign in to comment.