aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-10-06 22:48:31 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-10-06 22:48:31 +0200
commit497d652aa83ed81e04f9400ae84362642585dfca (patch)
treed2264864ed3eee9d9ed48a71ea2a26dbdd1db69f /src/main
parent023b44c71ea7739716ebd010cea2841e5336a69b (diff)
downloadskyhanni-497d652aa83ed81e04f9400ae84362642585dfca.tar.gz
skyhanni-497d652aa83ed81e04f9400ae84362642585dfca.tar.bz2
skyhanni-497d652aa83ed81e04f9400ae84362642585dfca.zip
code cleanup in the chat error repo logic
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/RepoErrorData.kt18
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt60
2 files changed, 38 insertions, 40 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/RepoErrorData.kt b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/RepoErrorData.kt
index 486617651..3ec529db3 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/RepoErrorData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/RepoErrorData.kt
@@ -1,10 +1,18 @@
package at.hannibal2.skyhanni.data.jsonobjects.repo
import com.google.gson.annotations.Expose
+import com.google.gson.annotations.SerializedName
-data class RepoErrorData(
- @Expose var messageExact: List<String>?,
- @Expose var messageStartsWith: List<String>?,
- @Expose var replaceMessage: String?,
- @Expose var affectedVersions: List<String> = listOf(),
+data class RepoErrorJson(
+ @Expose @SerializedName("changed_error_messages") val changedErrorMessages: List<RepoErrorData>,
)
+
+data class RepoErrorData(
+ @Expose @SerializedName("message_exact") private var rawMessageExact: List<String>?,
+ @Expose @SerializedName("message_starts_with") private var rawMessageStartsWith: List<String>?,
+ @Expose @SerializedName("replace_message") var replaceMessage: String?,
+ @Expose @SerializedName("affected_versions") var affectedVersions: List<String> = listOf(),
+) {
+ val messageExact by lazy { rawMessageExact ?: emptyList() }
+ val messageStartsWith by lazy { rawMessageStartsWith ?: emptyList() }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt
index e0fcf8fcb..7fed3ad02 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt
@@ -1,8 +1,8 @@
package at.hannibal2.skyhanni.test.command
import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.data.jsonobjects.repo.RepoErrorData
+import at.hannibal2.skyhanni.data.jsonobjects.repo.RepoErrorJson
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
@@ -12,7 +12,6 @@ import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.StringUtils
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TimeLimitedSet
-import at.hannibal2.skyhanni.utils.json.fromJson
import net.minecraft.client.Minecraft
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.minutes
@@ -24,6 +23,7 @@ object ErrorManager {
private val errorMessages = mutableMapOf<String, String>()
private val fullErrorMessages = mutableMapOf<String, String>()
private var cache = TimeLimitedSet<Pair<String, Int>>(10.minutes)
+ private var repoErrors: List<RepoErrorData> = emptyList()
private val breakAfter = listOf(
"at at.hannibal2.skyhanni.config.commands.Commands\$createCommand",
@@ -156,66 +156,56 @@ object ErrorManager {
val extraDataString = buildExtraDataString(extraData)
val rawMessage = message.removeColor()
- errorMessages[randomId] =
- "```\nSkyHanni ${SkyHanniMod.version}: $rawMessage\n \n$stackTrace\n$extraDataString```"
+ errorMessages[randomId] = "```\nSkyHanni ${SkyHanniMod.version}: $rawMessage\n \n$stackTrace\n$extraDataString```"
fullErrorMessages[randomId] =
"```\nSkyHanni ${SkyHanniMod.version}: $rawMessage\n(full stack trace)\n \n$fullStackTrace\n$extraDataString```"
+ val finalMessage = buildFinalMessage(message) ?: return
+ ChatUtils.clickableChat(
+ "§c[SkyHanni-${SkyHanniMod.version}]: $finalMessage Click here to copy the error into the clipboard.",
+ onClick = { copyError(randomId) },
+ "§eClick to copy!",
+ prefix = false,
+ )
+ }
+
+ private fun buildFinalMessage(message: String): String? {
var finalMessage = message
if (finalMessage.last() !in ".?!") {
finalMessage += "§c."
}
+ val rawMessage = message.removeColor()
var hideError = false
for (repoError in repoErrors) {
- for (s in repoError.messageStartsWith ?: listOf()) {
- if (rawMessage.startsWith(s)) {
+ for (string in repoError.messageStartsWith) {
+ if (rawMessage.startsWith(string)) {
hideError = true
}
}
- for (s in repoError.messageExact ?: listOf()) {
- if (rawMessage == s) {
+ for (string in repoError.messageExact) {
+ if (rawMessage == string) {
hideError = true
}
}
if (hideError) {
- if (repoError.replaceMessage != null) {
- finalMessage = repoError.replaceMessage!!
+ repoError.replaceMessage?.let {
+ finalMessage = it
hideError = false
}
break
}
}
- if (!hideError) {
- ChatUtils.clickableChat(
- "§c[SkyHanni-${SkyHanniMod.version}]: $finalMessage Click here to copy the error into the clipboard.",
- onClick = { copyError(randomId) },
- "§eClick to copy!",
- prefix = false,
- )
- }
-
+ return if (hideError) null else finalMessage
}
- private var repoErrors: List<RepoErrorData> = listOf()
-
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
- val chatErrors = event.repoLocation.resolve("chat_errors")
- repoErrors = if (chatErrors.exists()) {
- chatErrors.listFiles()
- .filter {
- it != null && it.isFile && it.canRead()
- }
- .map {
- ConfigManager.gson.fromJson<RepoErrorData>(it.readText())
- }.filter {
- SkyHanniMod.version in it.affectedVersions
- }
- } else {
- listOf()
- }
+ val data = event.getConstant<RepoErrorJson>("ChangedChatErrors")
+ val version = SkyHanniMod.version
+
+ repoErrors = data.changedErrorMessages.filter { version in it.affectedVersions }
}
private fun buildExtraDataString(extraData: Array<out Pair<String, Any?>>): String {