Skip to content

Commit

Permalink
Expanded Bridge Support to fit "name: message" format
Browse files Browse the repository at this point in the history
  • Loading branch information
inglettronald committed Oct 4, 2022
1 parent 2092d19 commit a29f809
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/dulkirmod/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ object Config : Vigilant(File("./config/dulkirmod/config.toml"), "DulkirMod", so
)
setCategoryDescription(
"Bridge",
"Expected format: (bridge bot user) > (sent message) - without any parenthesis."
"If your bridge format does not work, message me on discord and I can probably add it."
)
}
private object ConfigSorting : SortingBehavior() {
Expand Down
19 changes: 18 additions & 1 deletion src/main/kotlin/dulkirmod/events/ChatEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class ChatEvent {
private val guildFormat = "^(§2Guild|§3Officer) > (?:\\S+ )?([\\w§]{3,18})(?: §[a-z]\\[[A-Z]+])?§f: (\\w+) > .+".toRegex()
private val guildFormat = "^(§2Guild|§3Officer) > (?:\\S+ )?([\\w§]{3,18})(?: §[a-z0-9]\\[[A-Z]+])?§f: (\\w+) > .+".toRegex()
private val alternateFormat = "^(§2Guild|§3Officer) > (?:\\S+ )?([\\w§]{3,18})(?: §[a-z0-9]\\[[A-Z]+])?§f: (\\w+): .+".toRegex()
@SubscribeEvent(receiveCanceled = true, priority = EventPriority.LOW)
fun onChat(event: ClientChatReceivedEvent) {
if (event.type == 2.toByte()) {
Expand Down Expand Up @@ -40,5 +41,21 @@ class ChatEvent {
).setChatStyle(event.message.siblings[1].chatStyle.createShallowCopy())
}
}

// OTHER FORMAT
else if (alternateFormat matches message && Config.bridgeBot) {
val matchResult = alternateFormat.find(message)
val (prefix, name, playerName) = matchResult!!.destructured
if (stripColorCodes(name.lowercase()) == Config.botName.lowercase()) {
val newPrefix = if (prefix == "§2Guild") "§2Bridge" else "§3Bridge"
val color = if (Config.bridgeColor == 16) "§z" else EnumChatFormatting.values()[Config.bridgeColor]
event.message.siblings[0] = ChatComponentText(
"$newPrefix > $color$playerName§f: "
)
event.message.siblings[1] = ChatComponentText(
event.message.siblings[1].unformattedText.replace("$playerName: ", "")
).setChatStyle(event.message.siblings[1].chatStyle.createShallowCopy())
}
}
}
}

0 comments on commit a29f809

Please sign in to comment.