From c9eb62dedbec7a5a9f626ba778b14c951fac383e Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Fri, 21 Jul 2023 16:12:57 +0200 Subject: more makeAccessible usage --- .../hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt') diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt index d498d5e99..0e1c5e5e4 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.config.core.config.Position import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.test.command.CopyErrorCommand import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.makeAccessible import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.OSUtils import com.google.gson.JsonElement @@ -178,8 +179,7 @@ object SkyHanniConfigSearchResetCommand { val line = term.split(".").drop(1) var field: Field? = null for (entry in line) { - field = obj.javaClass.getField(entry) - field.isAccessible = true + field = obj.javaClass.getField(entry).makeAccessible() parentObject = obj obj = field.get(obj) } @@ -201,8 +201,7 @@ object SkyHanniConfigSearchResetCommand { val name = field.name val fieldName = "$parentName.$name" - field.isAccessible = true - val newObj = field.get(obj) + val newObj = field.makeAccessible().get(obj) map[fieldName] = newObj if (newObj != null) { if (newObj !is Boolean && newObj !is String && newObj !is Long && newObj !is Int && newObj !is Double) { @@ -243,8 +242,6 @@ object SkyHanniConfigSearchResetCommand { } } - private fun Field.makeAccessible() = also { isAccessible = true } - private fun Any.getObjectName(): String { if (this is Position) { val x = javaClass.getDeclaredField("x").makeAccessible().get(this) -- cgit