aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2022-03-12 14:53:23 +0700
committerWyvest <45589059+Wyvest@users.noreply.github.com>2022-03-12 14:53:23 +0700
commitdd0d2d6d5c0191861cab0611d9fc28d7f4edb088 (patch)
tree96d8b3e88821e42b9b0357ddda1c5170992a57e5 /src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt
parenteef8bab78435d86107d95951cc1da04317520d33 (diff)
downloadChatting-dd0d2d6d5c0191861cab0611d9fc28d7f4edb088.tar.gz
Chatting-dd0d2d6d5c0191861cab0611d9fc28d7f4edb088.tar.bz2
Chatting-dd0d2d6d5c0191861cab0611d9fc28d7f4edb088.zip
chat tabs documentation
Diffstat (limited to 'src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt')
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt61
1 files changed, 38 insertions, 23 deletions
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt
index 236ccf6..1e20b01 100644
--- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt
@@ -2,7 +2,6 @@ package cc.woverflow.chatting.chat
import cc.woverflow.chatting.gui.components.TabButton
import com.google.gson.annotations.SerializedName
-import kotlinx.coroutines.runBlocking
import net.minecraft.client.Minecraft
import net.minecraft.util.EnumChatFormatting
import net.minecraft.util.IChatComponent
@@ -16,28 +15,60 @@ data class ChatTab(
@SerializedName("ends") val endsWith: List<String>?,
val equals: List<String>?,
@SerializedName("regex") val uncompiledRegex: List<String>?,
- val prefix: String
+ @SerializedName("ignore_starts") val ignoreStartsWith: List<String>?,
+ @SerializedName("ignore_contains") val ignoreContains: List<String>?,
+ @SerializedName("ignore_ends") val ignoreEndsWith: List<String>?,
+ @SerializedName("ignore_equals") val ignoreEquals: List<String>?,
+ @SerializedName("ignore_regex") val uncompiledIgnoreRegex: List<String>?,
+ val prefix: String,
) {
lateinit var button: TabButton
lateinit var compiledRegex: ChatRegexes
+ lateinit var compiledIgnoreRegex: ChatRegexes
//Ugly hack to make GSON not make button / regex null
fun initialize() {
compiledRegex = ChatRegexes(uncompiledRegex)
+ compiledIgnoreRegex = ChatRegexes(uncompiledIgnoreRegex)
val width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(name)
- button = TabButton(653452, runBlocking {
+ button = TabButton(653452, run {
val returnValue = x - 2
x += 6 + width
- return@runBlocking returnValue
+ return@run returnValue
}, width + 4, 12, this)
}
fun shouldRender(chatComponent: IChatComponent): Boolean {
- if (startsWith == null && equals == null && endsWith == null && contains == null && uncompiledRegex == null) {
- return true
- }
val message =
if (unformatted) EnumChatFormatting.getTextWithoutFormattingCodes(chatComponent.unformattedText) else chatComponent.formattedText
+ ignoreStartsWith?.forEach {
+ if (message.startsWith(it)) {
+ return false
+ }
+ }
+ ignoreEquals?.forEach {
+ if (message == it) {
+ return false
+ }
+ }
+ ignoreEndsWith?.forEach {
+ if (message.endsWith(it)) {
+ return false
+ }
+ }
+ ignoreContains?.forEach {
+ if (message.contains(it)) {
+ return false
+ }
+ }
+ compiledIgnoreRegex.compiledRegexList.forEach {
+ if (it.matches(message)) {
+ return false
+ }
+ }
+ if (startsWith.isNullOrEmpty() && equals.isNullOrEmpty() && endsWith.isNullOrEmpty() && contains.isNullOrEmpty() && uncompiledRegex.isNullOrEmpty()) {
+ return true
+ }
equals?.forEach {
if (message == it) {
return true
@@ -66,22 +97,6 @@ data class ChatTab(
return false
}
- override fun equals(other: Any?): Boolean {
- return other is ChatTab && name == other.name && startsWith == other.startsWith && contains == other.contains && endsWith == other.endsWith && equals == other.equals && compiledRegex == other.compiledRegex
- }
-
- override fun hashCode(): Int {
- var result = name.hashCode()
- result = 31 * result + (startsWith?.hashCode() ?: 0)
- result = 31 * result + (contains?.hashCode() ?: 0)
- result = 31 * result + (endsWith?.hashCode() ?: 0)
- result = 31 * result + (equals?.hashCode() ?: 0)
- result = 31 * result + (uncompiledRegex?.hashCode() ?: 0)
- result = 31 * result + prefix.hashCode()
- result = 31 * result + button.hashCode()
- return result
- }
-
companion object {
private var x = 4
}