aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWyvest <45589059+Wyvest@users.noreply.github.com>2023-01-14 13:08:14 -0500
committerWyvest <45589059+Wyvest@users.noreply.github.com>2023-01-14 13:08:14 -0500
commit27aa4095270f943ddab2a4e4d370e225766c7ff7 (patch)
treef1d71fe46072cfab38ad833be96600bd26c04cb7
parent3470ee81c4444c5955f7899acce226dae14a3da4 (diff)
downloadChatting-27aa4095270f943ddab2a4e4d370e225766c7ff7.tar.gz
Chatting-27aa4095270f943ddab2a4e4d370e225766c7ff7.tar.bz2
Chatting-27aa4095270f943ddab2a4e4d370e225766c7ff7.zip
change directory of chat tabs and shortcuts
-rw-r--r--docs/chattabs.md15
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/Chatting.kt7
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt12
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt137
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt2
5 files changed, 94 insertions, 79 deletions
diff --git a/docs/chattabs.md b/docs/chattabs.md
index 4b9cde6..cb264e5 100644
--- a/docs/chattabs.md
+++ b/docs/chattabs.md
@@ -2,7 +2,7 @@
## Syntax
-The file for Chat Tabs is in `{MINECRAFT DIRECTORY}/W-OVERFLOW/Chatting/chattabs.json`. The default file will look
+The file for Chat Tabs is in `{MINECRAFT DIRECTORY}/OneConfig/profiles/{PROFILE}/chattabs.json`. However, Chatting versions below 1.4.2-beta5 use `{MINECRAFT DIRECTORY}/W-OVERFLOW/Chatting/chattabs.json`. The default file will look
something like this:
```json
@@ -104,11 +104,10 @@ something like this:
{
"enabled": true,
"name": "PM",
- "unformatted": true,
+ "unformatted": false,
"lowercase": false,
- "starts": [
- "To ",
- "From "
+ "regex": [
+ "^(?<type>§dTo|§dFrom) (?<prefix>.+): §r(?<message>§7.*)(?:§r)?$"
],
"color": 14737632,
"hovered_color": 16777120,
@@ -116,7 +115,7 @@ something like this:
"prefix": "/r "
}
],
- "version": 5
+ "version": 6
}
```
@@ -231,6 +230,10 @@ The `lowercase` property makes the message trigger lowercase.
## Chat Tabs JSON Changelogs
+### Version 6 (Chatting 1.4.2 beta5)
+- Changed PM tab to use regex instead of starts and sets `unformatted` to false
+- Changed directory of Chat Tabs JSON to `{MINECRAFT DIRECTORY}/OneConfig/profiles/{PROFILE}/chattabs.json`
+
### Version 5 (Chatting 1.4.0 [04363f5])
- The `prefix` property is no longer a required property.
- Added `lowercase` property
diff --git a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt
index d74dd6a..27f1a87 100644
--- a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt
@@ -67,12 +67,7 @@ object Chatting {
private val fileFormatter: SimpleDateFormat = SimpleDateFormat("yyyy-MM-dd_HH.mm.ss'.png'")
- val modDir = File(File(Minecraft.getMinecraft().mcDataDir, "W-OVERFLOW"), NAME)
-
- @Mod.EventHandler
- fun onFMLPreInitialization(event: FMLPreInitializationEvent) {
- if (!modDir.exists()) modDir.mkdirs()
- }
+ val oldModDir = File(File(Minecraft.getMinecraft().mcDataDir, "W-OVERFLOW"), NAME)
@Mod.EventHandler
fun onInitialization(event: FMLInitializationEvent) {
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt
index f3145de..6add813 100644
--- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt
@@ -1,12 +1,14 @@
package cc.woverflow.chatting.chat
+import cc.polyfrost.oneconfig.config.core.ConfigUtils
import cc.woverflow.chatting.Chatting
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import java.io.File
object ChatShortcuts {
- private val shortcutsFile = File(Chatting.modDir, "chatshortcuts.json")
+ private val oldShortcutsFile = File(Chatting.oldModDir, "chatshortcuts.json")
+ private val shortcutsFile = ConfigUtils.getProfileFile("chatshortcuts.json")
private val PARSER = JsonParser()
private var initialized = false
@@ -31,9 +33,13 @@ object ChatShortcuts {
}
if (!shortcutsFile.exists()) {
shortcutsFile.createNewFile()
- shortcutsFile.writeText(
+ if (oldShortcutsFile.exists()) {
+ shortcutsFile.writeText(
+ oldShortcutsFile.readText()
+ )
+ } else {
JsonObject().toString()
- )
+ }
} else {
val jsonObj = PARSER.parse(shortcutsFile.readText()).asJsonObject
for (shortcut in jsonObj.entrySet()) {
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
index b6027a7..cb95c53 100644
--- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatTabs.kt
@@ -1,5 +1,6 @@
package cc.woverflow.chatting.chat
+import cc.polyfrost.oneconfig.config.core.ConfigUtils
import cc.woverflow.chatting.Chatting
import cc.woverflow.chatting.gui.components.TabButton
import com.google.gson.GsonBuilder
@@ -26,7 +27,8 @@ object ChatTabs {
}
private var initialized = false
- private val tabFile = File(Chatting.modDir, "chattabs.json")
+ private val tabFile = ConfigUtils.getProfileFile("chattabs.json")
+ private val oldTabFile = File(Chatting.oldModDir, "chattabs.json")
fun initialize() {
if (initialized) {
@@ -35,78 +37,87 @@ object ChatTabs {
initialized = true
}
if (!tabFile.exists()) {
- generateNewFile()
+ if (oldTabFile.exists()) {
+ tabFile.writeText(oldTabFile.readText())
+ handleFile()
+ } else {
+ generateNewFile()
+ }
} else {
- try {
- val chatTabJson = GSON.fromJson(tabFile.readText(), ChatTabsJson::class.java)
- when (chatTabJson.version) {
- 1 -> {
- // ver 2 adds `enabled`
- chatTabJson.tabs.forEach {
- applyVersion2Changes(it.asJsonObject)
- applyVersion3Changes(it.asJsonObject)
- applyVersion4Changes(it.asJsonObject)
- applyVersion5Changes(it.asJsonObject)
- applyVersion6Changes(it.asJsonObject)
- }
- chatTabJson.version = ChatTabsJson.VERSION
- tabFile.writeText(GSON.toJson(chatTabJson))
- }
- 2 -> {
- // ver 3 adds ignore_
- chatTabJson.tabs.forEach {
- applyVersion3Changes(it.asJsonObject)
- applyVersion4Changes(it.asJsonObject)
- applyVersion5Changes(it.asJsonObject)
- applyVersion6Changes(it.asJsonObject)
- }
- chatTabJson.version = ChatTabsJson.VERSION
- tabFile.writeText(GSON.toJson(chatTabJson))
+ handleFile()
+ }
+ tabs.forEach {
+ it.initialize()
+ }
+ currentTab = tabs[0]
+ }
+
+ private fun handleFile() {
+ try {
+ val chatTabJson = GSON.fromJson(tabFile.readText(), ChatTabsJson::class.java)
+ when (chatTabJson.version) {
+ 1 -> {
+ // ver 2 adds `enabled`
+ chatTabJson.tabs.forEach {
+ applyVersion2Changes(it.asJsonObject)
+ applyVersion3Changes(it.asJsonObject)
+ applyVersion4Changes(it.asJsonObject)
+ applyVersion5Changes(it.asJsonObject)
+ applyVersion6Changes(it.asJsonObject)
}
- 3 -> {
- // ver 4 adds color options
- chatTabJson.tabs.forEach {
- applyVersion4Changes(it.asJsonObject)
- applyVersion5Changes(it.asJsonObject)
- applyVersion6Changes(it.asJsonObject)
- }
- chatTabJson.version = ChatTabsJson.VERSION
- tabFile.writeText(GSON.toJson(chatTabJson))
+ chatTabJson.version = ChatTabsJson.VERSION
+ tabFile.writeText(GSON.toJson(chatTabJson))
+ }
+ 2 -> {
+ // ver 3 adds ignore_
+ chatTabJson.tabs.forEach {
+ applyVersion3Changes(it.asJsonObject)
+ applyVersion4Changes(it.asJsonObject)
+ applyVersion5Changes(it.asJsonObject)
+ applyVersion6Changes(it.asJsonObject)
}
- 4 -> {
- // ver 5 adds lowercase
- chatTabJson.tabs.forEach {
- applyVersion5Changes(it.asJsonObject)
- applyVersion6Changes(it.asJsonObject)
- }
- chatTabJson.version = ChatTabsJson.VERSION
- tabFile.writeText(GSON.toJson(chatTabJson))
+ chatTabJson.version = ChatTabsJson.VERSION
+ tabFile.writeText(GSON.toJson(chatTabJson))
+ }
+ 3 -> {
+ // ver 4 adds color options
+ chatTabJson.tabs.forEach {
+ applyVersion4Changes(it.asJsonObject)
+ applyVersion5Changes(it.asJsonObject)
+ applyVersion6Changes(it.asJsonObject)
}
- 5 -> {
- // ver 6 changes pm regex
- chatTabJson.tabs.forEach {
- applyVersion6Changes(it.asJsonObject)
- }
- chatTabJson.version = ChatTabsJson.VERSION
- tabFile.writeText(GSON.toJson(chatTabJson))
+ chatTabJson.version = ChatTabsJson.VERSION
+ tabFile.writeText(GSON.toJson(chatTabJson))
+ }
+ 4 -> {
+ // ver 5 adds lowercase
+ chatTabJson.tabs.forEach {
+ applyVersion5Changes(it.asJsonObject)
+ applyVersion6Changes(it.asJsonObject)
}
+ chatTabJson.version = ChatTabsJson.VERSION
+ tabFile.writeText(GSON.toJson(chatTabJson))
}
- chatTabJson.tabs.forEach {
- val chatTab = GSON.fromJson(it.toString(), ChatTab::class.java)
- if (chatTab.enabled) {
- tabs.add(chatTab)
+ 5 -> {
+ // ver 6 changes pm regex
+ chatTabJson.tabs.forEach {
+ applyVersion6Changes(it.asJsonObject)
}
+ chatTabJson.version = ChatTabsJson.VERSION
+ tabFile.writeText(GSON.toJson(chatTabJson))
}
- } catch (e: Throwable) {
- e.printStackTrace()
- tabFile.delete()
- generateNewFile()
}
+ chatTabJson.tabs.forEach {
+ val chatTab = GSON.fromJson(it.toString(), ChatTab::class.java)
+ if (chatTab.enabled) {
+ tabs.add(chatTab)
+ }
+ }
+ } catch (e: Throwable) {
+ e.printStackTrace()
+ tabFile.delete()
+ generateNewFile()
}
- tabs.forEach {
- it.initialize()
- }
- currentTab = tabs[0]
}
private fun applyVersion2Changes(json: JsonObject) {
diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
index 55195ce..ab52eb9 100644
--- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
@@ -20,7 +20,7 @@ object ChattingConfig : Config(
Mod(
Chatting.NAME,
ModType.UTIL_QOL,
- VigilanceMigrator(File(Chatting.modDir, Chatting.ID + ".toml").toPath().toString())
+ VigilanceMigrator(File(Chatting.oldModDir, Chatting.ID + ".toml").toPath().toString())
), "chatting.json"
) {