diff options
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/RepoErrorData.kt | 10 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt | 64 |
2 files changed, 68 insertions, 6 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 new file mode 100644 index 000000000..486617651 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/RepoErrorData.kt @@ -0,0 +1,10 @@ +package at.hannibal2.skyhanni.data.jsonobjects.repo + +import com.google.gson.annotations.Expose + +data class RepoErrorData( + @Expose var messageExact: List<String>?, + @Expose var messageStartsWith: List<String>?, + @Expose var replaceMessage: String?, + @Expose var affectedVersions: List<String> = listOf(), +) 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 56a50eceb..e0fcf8fcb 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt @@ -1,6 +1,10 @@ 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.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzUtils @@ -8,9 +12,12 @@ 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 +@SkyHanniModule object ErrorManager { // random id -> error message @@ -158,12 +165,57 @@ object ErrorManager { if (finalMessage.last() !in ".?!") { finalMessage += "§c." } - ChatUtils.clickableChat( - "§c[SkyHanni-${SkyHanniMod.version}]: $finalMessage Click here to copy the error into the clipboard.", - onClick = { copyError(randomId) }, - "§eClick to copy!", - prefix = false, - ) + + var hideError = false + for (repoError in repoErrors) { + for (s in repoError.messageStartsWith ?: listOf()) { + if (rawMessage.startsWith(s)) { + hideError = true + } + } + for (s in repoError.messageExact ?: listOf()) { + if (rawMessage == s) { + hideError = true + } + } + if (hideError) { + if (repoError.replaceMessage != null) { + finalMessage = repoError.replaceMessage!! + 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, + ) + } + + } + + 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() + } } private fun buildExtraDataString(extraData: Array<out Pair<String, Any?>>): String { |