aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/cc/woverflow/chatting/chat
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
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')
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTab.kt61
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt54
2 files changed, 84 insertions, 31 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
}
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
index 5525a51..ec9dfc8 100644
--- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
@@ -37,13 +37,24 @@ object ChatTabs {
} else {
try {
val chatTabJson = GSON.fromJson(tabFile.readText(), ChatTabsJson::class.java)
- if (chatTabJson.version == 1) {
- // ver 2 adds `enabled`
- chatTabJson.tabs.forEach {
- it.asJsonObject.addProperty("enabled", true)
+ when (chatTabJson.version) {
+ 1 -> {
+ // ver 2 adds `enabled`
+ chatTabJson.tabs.forEach {
+ applyVersion2Changes(it.asJsonObject)
+ applyVersion3Changes(it.asJsonObject)
+ }
+ chatTabJson.version = 3
+ tabFile.writeText(chatTabJson.toString())
+ }
+ 2 -> {
+ // ver 2 adds `enabled`
+ chatTabJson.tabs.forEach {
+ applyVersion3Changes(it.asJsonObject)
+ }
+ chatTabJson.version = 3
+ tabFile.writeText(chatTabJson.toString())
}
- chatTabJson.version = 2
- tabFile.writeText(chatTabJson.toString())
}
chatTabJson.tabs.forEach {
val chatTab = GSON.fromJson(it.toString(), ChatTab::class.java)
@@ -63,6 +74,18 @@ object ChatTabs {
currentTab = tabs[0]
}
+ private fun applyVersion2Changes(json: JsonObject) {
+ json.addProperty("enabled", true)
+ }
+
+ private fun applyVersion3Changes(json: JsonObject) {
+ json.add("ignore_starts", JsonArray())
+ json.add("ignore_contains", JsonArray())
+ json.add("ignore_ends", JsonArray())
+ json.add("ignore_equals", JsonArray())
+ json.add("ignore_regex", JsonArray())
+ }
+
fun shouldRender(message: IChatComponent): Boolean {
return currentTab?.shouldRender(message) ?: true
}
@@ -72,12 +95,12 @@ object ChatTabs {
val jsonObject = JsonObject()
val defaultTabs = generateDefaultTabs()
jsonObject.add("tabs", defaultTabs)
- jsonObject.addProperty("version", 1)
+ jsonObject.addProperty("version", 3)
tabFile.writeText(jsonObject.toString())
}
private fun generateDefaultTabs(): JsonArray {
- val all = ChatTab(true, "ALL", false, null, null, null, null, null, "")
+ val all = ChatTab(true, "ALL", false, null, null, null, null, null, null, null, null, null, null, "")
val party = ChatTab(
true,
"PARTY",
@@ -136,6 +159,11 @@ object ChatTabs {
"§cThis party is currently muted\\.§r",
"(§r)*(§9P §8\u003e)+(.*)"
),
+ null,
+ null,
+ null,
+ null,
+ null,
"/pc "
)
val guild = ChatTab(
@@ -147,6 +175,11 @@ object ChatTabs {
null,
null,
null,
+ null,
+ null,
+ null,
+ null,
+ null,
"/gc "
)
val pm = ChatTab(
@@ -158,6 +191,11 @@ object ChatTabs {
null,
null,
null,
+ null,
+ null,
+ null,
+ null,
+ null,
"/r "
)
tabs.add(all)