aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/bingo
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-03-23 15:38:34 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-03-23 15:38:34 +0100
commit53303c391dc335bc676263f5be75bcc110a74446 (patch)
treebbac55772616c16d041d4753ecd36565441286cb /src/main/java/at/hannibal2/skyhanni/features/bingo
parentafb4dae8eda1403079d73480dd3621d5e361f21f (diff)
downloadskyhanni-53303c391dc335bc676263f5be75bcc110a74446.tar.gz
skyhanni-53303c391dc335bc676263f5be75bcc110a74446.tar.bz2
skyhanni-53303c391dc335bc676263f5be75bcc110a74446.zip
removed toMutableList in render list logic and prevent ConcurrentModificationException
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/bingo')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt21
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt15
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt36
3 files changed, 48 insertions, 24 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt
index f88ec4b59..d97e1c42e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt
@@ -26,7 +26,7 @@ class BingoCardDisplay {
private val MAX_COMMUNITY_GOALS = 5
private var tick = 0
- private val display = mutableListOf<String>()
+ private var display = listOf<String>()
private val config get() = SkyHanniMod.feature.bingo
private val goalCompletePattern = Pattern.compile("§6§lBINGO GOAL COMPLETE! §r§e(.*)")
@@ -121,20 +121,25 @@ class BingoCardDisplay {
}
private fun update() {
- display.clear()
+ display = drawDisplay()
+ }
+
+ private fun drawDisplay(): MutableList<String> {
+ val newList = mutableListOf<String>()
- display.add("Community Goals")
+ newList.add("Community Goals")
if (communityGoals.isEmpty()) {
- display.add("§cOpen the §e/bingo §ccard.")
+ newList.add("§cOpen the §e/bingo §ccard.")
} else {
- communityGoals.mapTo(display) { " " + it.description + if (it.done) " §aDONE" else "" }
+ communityGoals.mapTo(newList) { " " + it.description + if (it.done) " §aDONE" else "" }
val todo = personalGoals.filter { !it.done }
val done = MAX_PERSONAL_GOALS - todo.size
- display.add(" ")
- display.add("Personal Goals: ($done/$MAX_PERSONAL_GOALS done)")
- todo.mapTo(display) { " " + it.description }
+ newList.add(" ")
+ newList.add("Personal Goals: ($done/$MAX_PERSONAL_GOALS done)")
+ todo.mapTo(newList) { " " + it.description }
}
+ return newList
}
private var lastSneak = false
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt
index 75c755de3..af909605e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt
@@ -28,7 +28,7 @@ class BingoNextStepHelper {
companion object {
private val finalSteps = mutableListOf<NextStep>()
private val currentSteps = mutableListOf<NextStep>()
- val currentHelp = mutableListOf<String>()
+ var currentHelp = listOf<String>()
fun command() {
updateResult(true)
@@ -42,18 +42,23 @@ class BingoNextStepHelper {
if (print) println()
}
- currentHelp.clear()
- currentHelp.add("Bingo Step Helper")
+ currentHelp = drawDisplay(print)
+ }
+
+ private fun drawDisplay(print: Boolean): MutableList<String> {
+ val newCurrentHelp = mutableListOf<String>()
+ newCurrentHelp.add("Bingo Step Helper")
if (currentSteps.isEmpty()) {
- currentHelp.add("§cOpen the §e/bingo §ccard.")
+ newCurrentHelp.add("§cOpen the §e/bingo §ccard.")
}
for (currentStep in currentSteps) {
val text = getName(currentStep)
- currentHelp.add(" §7$text")
+ newCurrentHelp.add(" §7$text")
if (print) println(text)
}
if (print) println()
+ return newCurrentHelp
}
private fun printRequirements(step: NextStep, print: Boolean, parentDone: Boolean = false, depth: Int = 0) {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt
index b27a6290e..7662a434f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt
@@ -24,7 +24,7 @@ class MinionCraftHelper {
private var minionNamePattern = Pattern.compile("(.*) Minion (.*)")
private var tick = 0
- private var display = mutableListOf<String>()
+ private var display = listOf<String>()
private var hasMinionInInventory = false
private var hasItemsForMinion = false
private val tierOneMinions = mutableListOf<String>()
@@ -56,7 +56,7 @@ class MinionCraftHelper {
}
if (!hasMinionInInventory && !hasItemsForMinion) {
- display.clear()
+ display = emptyList()
return
}
@@ -67,14 +67,22 @@ class MinionCraftHelper {
val (minions, otherItems) = loadFromInventory(mainInventory)
- display.clear()
+ display = drawDisplay(minions, otherItems)
+ }
+
+ private fun drawDisplay(
+ minions: MutableMap<String, String>,
+ otherItems: MutableMap<String, Int>,
+ ): MutableList<String> {
+ val newDisplay = mutableListOf<String>()
for ((minionName, minionId) in minions) {
val matcher = minionNamePattern.matcher(minionName)
- if (!matcher.matches()) return
+ if (!matcher.matches()) continue
val cleanName = matcher.group(1).removeColor()
val number = matcher.group(2).romanToDecimalIfNeeded()
- addMinion(cleanName, number, minionId, otherItems)
+ addMinion(cleanName, number, minionId, otherItems, newDisplay)
}
+ return newDisplay
}
@SubscribeEvent
@@ -185,10 +193,16 @@ class MinionCraftHelper {
}
}
- private fun addMinion(name: String, minionTier: Int, minionId: String, otherItems: MutableMap<String, Int>) {
+ private fun addMinion(
+ name: String,
+ minionTier: Int,
+ minionId: String,
+ otherItems: MutableMap<String, Int>,
+ newDisplay: MutableList<String>,
+ ) {
val nextTier = minionTier + 1
val minionName = "§9$name Minion $nextTier"
- display.add(minionName)
+ newDisplay.add(minionName)
val nextMinionId = minionId.addOneToId()
for (recipe in NEUItems.getRecipes(nextMinionId)) {
if (recipe !is CraftingRecipe) continue
@@ -213,19 +227,19 @@ class MinionCraftHelper {
val itemName = NEUItems.getItemStack(rawId).name ?: "§cName??§f"
if (percentage >= 1) {
val color = if (itemId.startsWith("WOOD_")) "§7" else "§a"
- display.add(" $itemName§8: ${color}DONE")
+ newDisplay.add(" $itemName§8: ${color}DONE")
otherItems[itemId] = have - needAmount
} else {
val format = LorenzUtils.formatPercentage(percentage)
val haveFormat = LorenzUtils.formatInteger(have)
val needFormat = LorenzUtils.formatInteger(needAmount)
- display.add("$itemName§8: §e$format §8(§7$haveFormat§8/§7$needFormat§8)")
+ newDisplay.add("$itemName§8: §e$format §8(§7$haveFormat§8/§7$needFormat§8)")
allDone = false
}
}
- display.add(" ")
+ newDisplay.add(" ")
if (allDone) {
- addMinion(name, nextTier, nextMinionId, otherItems)
+ addMinion(name, nextTier, nextMinionId, otherItems, newDisplay)
notify(minionName)
}
}