aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/cc/woverflow
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/cc/woverflow')
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt47
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt2
2 files changed, 45 insertions, 4 deletions
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
index 62c2760..b6027a7 100644
--- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
@@ -6,6 +6,7 @@ import com.google.gson.GsonBuilder
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import com.google.gson.JsonParser
+import com.google.gson.JsonPrimitive
import net.minecraft.client.Minecraft
import net.minecraft.util.IChatComponent
import java.io.File
@@ -46,6 +47,7 @@ object ChatTabs {
applyVersion3Changes(it.asJsonObject)
applyVersion4Changes(it.asJsonObject)
applyVersion5Changes(it.asJsonObject)
+ applyVersion6Changes(it.asJsonObject)
}
chatTabJson.version = ChatTabsJson.VERSION
tabFile.writeText(GSON.toJson(chatTabJson))
@@ -56,6 +58,7 @@ object ChatTabs {
applyVersion3Changes(it.asJsonObject)
applyVersion4Changes(it.asJsonObject)
applyVersion5Changes(it.asJsonObject)
+ applyVersion6Changes(it.asJsonObject)
}
chatTabJson.version = ChatTabsJson.VERSION
tabFile.writeText(GSON.toJson(chatTabJson))
@@ -65,6 +68,7 @@ object ChatTabs {
chatTabJson.tabs.forEach {
applyVersion4Changes(it.asJsonObject)
applyVersion5Changes(it.asJsonObject)
+ applyVersion6Changes(it.asJsonObject)
}
chatTabJson.version = ChatTabsJson.VERSION
tabFile.writeText(GSON.toJson(chatTabJson))
@@ -73,6 +77,15 @@ object ChatTabs {
// ver 5 adds lowercase
chatTabJson.tabs.forEach {
applyVersion5Changes(it.asJsonObject)
+ applyVersion6Changes(it.asJsonObject)
+ }
+ chatTabJson.version = ChatTabsJson.VERSION
+ tabFile.writeText(GSON.toJson(chatTabJson))
+ }
+ 5 -> {
+ // ver 6 changes pm regex
+ chatTabJson.tabs.forEach {
+ applyVersion6Changes(it.asJsonObject)
}
chatTabJson.version = ChatTabsJson.VERSION
tabFile.writeText(GSON.toJson(chatTabJson))
@@ -118,6 +131,34 @@ object ChatTabs {
json.addProperty("lowercase", false)
}
+ private fun applyVersion6Changes(json: JsonObject) {
+ if (json.has("starts")) {
+ val starts = json["starts"].asJsonArray
+ var detected = false
+ starts.iterator().let {
+ while (it.hasNext()) {
+ when (it.next().asString) {
+ "To " -> {
+ detected = true
+ it.remove()
+ }
+ "From " -> {
+ detected = true
+ it.remove()
+ }
+ }
+ }
+ }
+ if (detected) {
+ json.add("regex", JsonArray().apply {
+ add(JsonPrimitive("^(?<type>§dTo|§dFrom) (?<prefix>.+): §r(?<message>§7.*)(?:§r)?\$"))
+ })
+ json.remove("unformatted")
+ json.addProperty("unformatted", false)
+ }
+ }
+ }
+
fun shouldRender(message: IChatComponent): Boolean {
return currentTab?.shouldRender(message) ?: true
}
@@ -244,13 +285,13 @@ object ChatTabs {
val pm = ChatTab(
true,
"PM",
- unformatted = true,
+ unformatted = false,
lowercase = false,
- startsWith = listOf("To ", "From "),
+ startsWith = null,
contains = null,
endsWith = null,
equals = null,
- uncompiledRegex = null,
+ uncompiledRegex = listOf("^(?<type>§dTo|§dFrom) (?<prefix>.+): §r(?<message>§7.*)(?:§r)?\$"),
ignoreStartsWith = null,
ignoreContains = null,
ignoreEndsWith = null,
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt
index b239bbd..c632561 100644
--- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabsJson.kt
@@ -10,6 +10,6 @@ data class ChatTabsJson(@SerializedName("tabs") val tabs: JsonArray, var version
}
companion object {
- const val VERSION = 5
+ const val VERSION = 6
}
} \ No newline at end of file