aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-21 17:51:25 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-21 17:51:25 +0200
commitce144f7d52e1e30d145619646003fb3c86828418 (patch)
tree252c873a6de94407612db674a1f6277605ce4c60 /src/main
parente53d62786409b7441e4ff9c2978d3ce1fdd94339 (diff)
downloadskyhanni-ce144f7d52e1e30d145619646003fb3c86828418.tar.gz
skyhanni-ce144f7d52e1e30d145619646003fb3c86828418.tar.bz2
skyhanni-ce144f7d52e1e30d145619646003fb3c86828418.zip
warns before changing more than 3 config elements
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt
index c69600f25..279d58e2c 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt
@@ -16,8 +16,12 @@ import java.lang.reflect.Field
import java.lang.reflect.Modifier
object SkyHanniConfigSearchResetCommand {
+
+ private var lastCommand = emptyArray<String>()
+
fun command(args: Array<String>) {
LorenzUtils.chat(runCommand(args))
+ lastCommand = args
}
private fun runCommand(args: Array<String>): String {
@@ -43,6 +47,11 @@ object SkyHanniConfigSearchResetCommand {
return try {
val (field, defaultObject, _) = getComplexField(term, Features())
val (_, _, parent) = getComplexField(term, SkyHanniMod.feature)
+ val affectedElements = findConfigElements({ it.startsWith("$term.") }, { true }).size
+ if (affectedElements > 3 && !args.contentEquals(lastCommand)) {
+ return "§cThis will change $affectedElements config elements! Use the command again to confirm."
+ }
+ println("size: $affectedElements")
field.set(parent, defaultObject)
"§eSuccessfully reset config element '$term'"
} catch (e: Exception) {
@@ -79,6 +88,11 @@ object SkyHanniConfigSearchResetCommand {
ProfileStorageData.profileSpecific ?: return "§cprofileSpecific is null!"
} else return "§cUnknown config location!"
+ val affectedElements = findConfigElements({ it.startsWith("$term.") }, { true }).size
+ if (affectedElements > 3 && !args.contentEquals(lastCommand)) {
+ return "§cThis will change $affectedElements config elements! Use the command again to confirm."
+ }
+
val element = ConfigManager.gson.fromJson(rawJson, JsonElement::class.java)
val list = term.split(".").drop(1)
val shimmy = Shimmy.makeShimmy(root, list) ?: return "§cCould not change config element '$term', not found!"
@@ -197,7 +211,7 @@ object SkyHanniConfigSearchResetCommand {
return map
}
for (field in obj.javaClass.fields) {
- if ((field.modifiers and Modifier.STATIC) == 0) continue
+ if ((field.modifiers and Modifier.STATIC) != 0) continue
val name = field.name
val fieldName = "$parentName.$name"