aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorWalker Selby <git@walkerselby.com>2023-10-28 18:15:18 +0100
committerGitHub <noreply@github.com>2023-10-28 19:15:18 +0200
commit9a20410721f0c65a74e0669954b21e373c3c0eb0 (patch)
tree1d3745de3d22d4484ac7e5ecddaf31c7267d6346 /src/main/java/at/hannibal2/skyhanni
parent9990094370612b8523c8f2622399d01c5697c0a7 (diff)
downloadskyhanni-9a20410721f0c65a74e0669954b21e373c3c0eb0.tar.gz
skyhanni-9a20410721f0c65a74e0669954b21e373c3c0eb0.tar.bz2
skyhanni-9a20410721f0c65a74e0669954b21e373c3c0eb0.zip
Refactor StatsTuning.kt (#594)
Reducing cognitive complexity in StatsTuning.kt #594
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt120
1 files changed, 67 insertions, 53 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt
index ff0e6f41d..270acbd6f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/StatsTuning.kt
@@ -11,6 +11,7 @@ import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -24,71 +25,83 @@ class StatsTuning {
val stack = event.stack
- if (config.templateStats && inventoryName == "Stats Tuning") {
- val name = stack.name ?: return
- if (name == "§aLoad") {
- var grab = false
- val list = mutableListOf<String>()
- for (line in stack.getLore()) {
- if (line == "§7You are loading:") {
- grab = true
+ if (config.templateStats && inventoryName == "Stats Tuning") if (templateStats(stack, event)) return
+ if (config.selectedStats && inventoryName == "Accessory Bag Thaumaturgy") if (selectedStats(
+ stack,
+ event
+ )
+ ) return
+ if (config.points && inventoryName == "Stats Tuning") points(stack, event)
+
+ }
+
+ private fun templateStats(stack: ItemStack, event: RenderInventoryItemTipEvent): Boolean {
+ val name = stack.name ?: return true
+ if (name == "§aLoad") {
+ var grab = false
+ val list = mutableListOf<String>()
+ for (line in stack.getLore()) {
+ if (line == "§7You are loading:") {
+ grab = true
+ continue
+ }
+ if (grab) {
+ if (line == "") {
+ grab = false
continue
}
- if (grab) {
- if (line == "") {
- grab = false
- continue
- }
- val text = line.split(":")[0]
- list.add(text)
- }
- }
- if (list.isNotEmpty()) {
- event.stackTip = list.joinToString(" + ")
- event.offsetX = 20
- event.offsetY = -5
- event.alignLeft = false
- return
+ val text = line.split(":")[0]
+ list.add(text)
}
}
+ if (list.isNotEmpty()) {
+ event.stackTip = list.joinToString(" + ")
+ event.offsetX = 20
+ event.offsetY = -5
+ event.alignLeft = false
+ return true
+ }
}
- if (config.selectedStats && inventoryName == "Accessory Bag Thaumaturgy") {
- val name = stack.name ?: return
- if (name == "§aStats Tuning") {
- var grab = false
- val list = mutableListOf<String>()
- for (line in stack.getLore()) {
- if (line == "§7Your tuning:") {
- grab = true
+ return false
+ }
+
+ private fun selectedStats(stack: ItemStack, event: RenderInventoryItemTipEvent): Boolean {
+ val name = stack.name ?: return true
+ if (name == "§aStats Tuning") {
+ var grab = false
+ val list = mutableListOf<String>()
+ for (line in stack.getLore()) {
+ if (line == "§7Your tuning:") {
+ grab = true
+ continue
+ }
+ if (grab) {
+ if (line == "") {
+ grab = false
continue
}
- if (grab) {
- if (line == "") {
- grab = false
- continue
- }
- val text = line.split(":")[0].split(" ")[0] + "§7"
- list.add(text)
- }
- }
- if (list.isNotEmpty()) {
- event.stackTip = list.joinToString(" + ")
- event.offsetX = 3
- event.offsetY = -5
- event.alignLeft = false
- return
+ val text = line.split(":")[0].split(" ")[0] + "§7"
+ list.add(text)
}
}
- }
- if (config.points && inventoryName == "Stats Tuning") {
- for (line in stack.getLore()) {
- patternStatPoints.matchMatcher(line) {
- val points = group("amount")
- event.stackTip = points
- }
+ if (list.isNotEmpty()) {
+ event.stackTip = list.joinToString(" + ")
+ event.offsetX = 3
+ event.offsetY = -5
+ event.alignLeft = false
+ return true
}
}
+ return false
+ }
+ private fun points(stack: ItemStack, event: RenderInventoryItemTipEvent) {
+ for (line in stack.getLore()) {
+ patternStatPoints.matchMatcher(line) {
+ val points = group("amount")
+ event.stackTip = points
+ }
+ }
}
@SubscribeEvent(priority = EventPriority.LOW)
@@ -107,6 +120,7 @@ class StatsTuning {
}
}
}
+
@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(3, "inventory.statsTuningSelectedStats", "inventory.statsTuning.selectedStats")