11package cc.woverflow.crashpatch.crashes
22
3- import com.google.gson.JsonArray
4- import gg.essential.api.utils.WebUtil
3+ import cc.woverflow.crashpatch.CrashPatch
4+ import cc.woverflow.crashpatch.logger
55import cc.woverflow.crashpatch.utils.asJsonObject
66import cc.woverflow.crashpatch.utils.get
77import cc.woverflow.crashpatch.utils.keys
8+ import com.google.gson.JsonArray
9+ import gg.essential.api.utils.WebUtil
810import java.util.regex.Pattern
911
1012object CrashHelper {
@@ -14,7 +16,7 @@ object CrashHelper {
1416 @JvmStatic
1517 fun scanReport (report : String ): CrashScan ? {
1618 try {
17- val responses = getResponses(report)
19+ val responses = if ( ! CrashPatch .useOldRepo) getResponses(report) else getOldResponses (report)
1820
1921 if (responses.isEmpty()) return null
2022 return CrashScan (responses)
@@ -25,6 +27,45 @@ object CrashHelper {
2527 }
2628
2729 private fun getResponses (report : String ): Map <String , ArrayList <String >> {
30+ val issues = WebUtil .fetchString(" https://raw.githubusercontent.com/SkyblockClient/CrashData/main/crashes.json" )?.asJsonObject() ? : return emptyMap()
31+ val responses = linkedMapOf<String , ArrayList <String >>()
32+
33+ val fixTypes = issues[" fixtypes" ].asJsonArray
34+ for (type in fixTypes) {
35+ responses[type.asJsonObject[" name" ].asString] = arrayListOf ()
36+ }
37+
38+ val fixes = issues[" fixes" ].asJsonArray
39+
40+ for (solution in fixes) {
41+ val solutionJson = solution.asJsonObject
42+ val causes = solutionJson[" causes" ].asJsonArray
43+ var trigger = false
44+ for (cause in causes) {
45+ val causeJson = cause.asJsonObject
46+ when (causeJson[" method" ].asString) {
47+ " contains" -> {
48+ if (report.contains(causeJson[" value" ].asString)) {
49+ trigger = true
50+ }
51+ }
52+ " regex" -> {
53+ if (Pattern .compile(causeJson[" value" ].asString, Pattern .CASE_INSENSITIVE ).matcher(report).find()) {
54+ trigger = true
55+ }
56+ }
57+ }
58+ }
59+ if (trigger) {
60+ responses[ArrayList (responses.keys)[if (solutionJson.has(" fixtype" )) solutionJson[" fixtype" ].asInt else 0 ]]?.add(solutionJson[" fix" ].asString)
61+ }
62+ }
63+ return responses
64+ }
65+
66+
67+ private fun getOldResponses (report : String ): Map <String , ArrayList <String >> {
68+ logger.warn(" Using the isXander MinecraftIssues repo is not supported! Use at your own risk." )
2869 val issues = WebUtil .fetchString(" https://raw.githubusercontent.com/isXander/MinecraftIssues/main/issues.json" )?.asJsonObject() ? : return linkedMapOf()
2970 val responses = linkedMapOf<String , ArrayList <String >>()
3071
0 commit comments