aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorNopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com>2024-10-07 07:43:06 +1100
committerGitHub <noreply@github.com>2024-10-06 22:43:06 +0200
commit023b44c71ea7739716ebd010cea2841e5336a69b (patch)
treef3ad5be27448d533449a0330d5422e7f6b4c4f57 /src/main/java
parent4df35d062a41f0e8fed82caf2249c2e71f5b4058 (diff)
downloadskyhanni-023b44c71ea7739716ebd010cea2841e5336a69b.tar.gz
skyhanni-023b44c71ea7739716ebd010cea2841e5336a69b.tar.bz2
skyhanni-023b44c71ea7739716ebd010cea2841e5336a69b.zip
Added the ability to disable chat errors via the repo (#2668)
Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/RepoErrorData.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/command/ErrorManager.kt64
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 {