diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-01-01 22:11:34 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-01-01 22:11:34 +0700 |
commit | cc4a11c7943d9036dc71679eaa531832cd2a2f0c (patch) | |
tree | da242580d43fa6f26f0b0b04deab82c200a5bb16 /src/main/kotlin/com/raeids/stratus/chat/ChatShortcuts.kt | |
parent | 856df4d08d3c392b35f256966f6263da86fdb7ab (diff) | |
download | Chatting-cc4a11c7943d9036dc71679eaa531832cd2a2f0c.tar.gz Chatting-cc4a11c7943d9036dc71679eaa531832cd2a2f0c.tar.bz2 Chatting-cc4a11c7943d9036dc71679eaa531832cd2a2f0c.zip |
Chattils 1.0.0
Diffstat (limited to 'src/main/kotlin/com/raeids/stratus/chat/ChatShortcuts.kt')
-rw-r--r-- | src/main/kotlin/com/raeids/stratus/chat/ChatShortcuts.kt | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/src/main/kotlin/com/raeids/stratus/chat/ChatShortcuts.kt b/src/main/kotlin/com/raeids/stratus/chat/ChatShortcuts.kt deleted file mode 100644 index 68fc18e..0000000 --- a/src/main/kotlin/com/raeids/stratus/chat/ChatShortcuts.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.raeids.stratus.chat - -import com.google.gson.JsonObject -import com.google.gson.JsonParser -import com.raeids.stratus.Stratus -import java.io.File - -object ChatShortcuts { - private val shortcutsFile = File(Stratus.modDir, "chatshortcuts.json") - private val PARSER = JsonParser() - - private var initialized = false - - val shortcuts = mutableSetOf<Pair<String, String>>() - - - fun initialize() { - if (initialized) { - return - } else { - initialized = true - } - if (!shortcutsFile.exists()) { - shortcutsFile.createNewFile() - shortcutsFile.writeText( - JsonObject().toString() - ) - } else { - val jsonObj = PARSER.parse(shortcutsFile.readText()).asJsonObject - for (shortcut in jsonObj.entrySet()) { - shortcuts.add(shortcut.key to shortcut.value.asString) - } - } - } - - fun removeShortcut(key: String) { - shortcuts.removeIf { it.first == key } - val jsonObj = PARSER.parse(shortcutsFile.readText()).asJsonObject - jsonObj.remove(key) - shortcutsFile.writeText(jsonObj.toString()) - } - - fun writeShortcut(key: String, value: String) { - shortcuts.add(key to value) - val jsonObj = PARSER.parse(shortcutsFile.readText()).asJsonObject - jsonObj.addProperty(key, value) - shortcutsFile.writeText(jsonObj.toString()) - } - - fun handleSentCommand(command: String): String { - shortcuts.forEach { - if (command == it.first || (command.startsWith(it.first) && command.substringAfter(it.first) - .startsWith(" ")) - ) { - return command.replaceFirst(it.first, it.second) - } - } - return command - } -}
\ No newline at end of file |