aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-21 16:12:57 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-07-21 16:12:57 +0200
commitc9eb62dedbec7a5a9f626ba778b14c951fac383e (patch)
tree0c3df4d8d9242e14dd77e3c7b4ae6858b1a9c530 /src/main/java/at
parent68c6bd4834cca0fe224074209ac90f04454e4850 (diff)
downloadskyhanni-c9eb62dedbec7a5a9f626ba778b14c951fac383e.tar.gz
skyhanni-c9eb62dedbec7a5a9f626ba778b14c951fac383e.tar.bz2
skyhanni-c9eb62dedbec7a5a9f626ba778b14c951fac383e.zip
more makeAccessible usage
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/SkyHanniConfigSearchResetCommand.kt9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt3
3 files changed, 11 insertions, 10 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt
index 5c7871a1e..2f21ebe03 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt
@@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
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.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.jsonobjects.ModsJson
import at.hannibal2.skyhanni.utils.renderables.Renderable
@@ -85,12 +86,12 @@ object QuickModMenuSwitch {
private fun handleAbstractGuis(openGui: String): String {
if (openGui == "gg.essential.vigilance.gui.SettingsGui") {
val clazz = Class.forName("gg.essential.vigilance.gui.SettingsGui")
- val titleBarDelegate = clazz.getDeclaredField("titleBar\$delegate").also { it.isAccessible = true }
+ val titleBarDelegate = clazz.getDeclaredField("titleBar\$delegate").makeAccessible()
.get(Minecraft.getMinecraft().currentScreen)
val titleBar =
- titleBarDelegate.javaClass.declaredFields[0].also { it.isAccessible = true }.get(titleBarDelegate)
- val gui = titleBar.javaClass.getDeclaredField("gui").also { it.isAccessible = true }.get(titleBar)
- val config = gui.javaClass.getDeclaredField("config").also { it.isAccessible = true }.get(gui)
+ titleBarDelegate.javaClass.declaredFields[0].makeAccessible().get(titleBarDelegate)
+ val gui = titleBar.javaClass.getDeclaredField("gui").makeAccessible().get(titleBar)
+ val config = gui.javaClass.getDeclaredField("config").makeAccessible().get(gui)
return config.javaClass.name
}
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)
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index e58d05fab..183cd78d7 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -21,6 +21,7 @@ import net.minecraft.event.HoverEvent
import net.minecraft.util.ChatComponentText
import org.lwjgl.input.Keyboard
import java.awt.Color
+import java.lang.reflect.Field
import java.text.DecimalFormat
import java.text.NumberFormat
import java.text.SimpleDateFormat
@@ -410,4 +411,6 @@ object LorenzUtils {
if (this == null) return emptyList()
return listOf(this)
}
+
+ fun Field.makeAccessible() = also { isAccessible = true }
} \ No newline at end of file