aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/garden
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/garden
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/garden')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/DicerRngDropCounter.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt13
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt35
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt20
8 files changed, 50 insertions, 44 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt
index 4e7853c38..d0d5d64f2 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt
@@ -18,7 +18,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent
import java.util.*
class CropMoneyDisplay {
- private val display = mutableListOf<List<Any>>()
+ private var display = mutableListOf<List<Any>>()
private val config get() = SkyHanniMod.feature.garden
private var tick = 0
private var loaded = false
@@ -52,9 +52,7 @@ class CropMoneyDisplay {
private fun update() {
init()
- val newDisplay = drawNewDisplay()
- display.clear()
- display.addAll(newDisplay)
+ display = drawNewDisplay()
}
private fun drawNewDisplay(): MutableList<List<Any>> {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/DicerRngDropCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/DicerRngDropCounter.kt
index ef1ee8a82..7e87b7b91 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/DicerRngDropCounter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/DicerRngDropCounter.kt
@@ -12,7 +12,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class DicerRngDropCounter {
- private val display = mutableListOf<String>()
+ private var display = listOf<String>()
private val drops = mutableMapOf<CropType, MutableMap<DropRarity, Int>>()
private val itemDrops = mutableListOf<ItemDrop>()
@@ -59,9 +59,7 @@ class DicerRngDropCounter {
}
private fun update() {
- val newDisplay = drawDisplay()
- display.clear()
- display.addAll(newDisplay)
+ display = drawDisplay()
}
private fun drawDisplay(): List<String> {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt
index 4eac3e0bb..d8bc15e16 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt
@@ -61,7 +61,7 @@ class EliteFarmingWeight {
private val config get() = SkyHanniMod.feature.garden
private val localCounter = mutableMapOf<CropType, Long>()
- private var display = mutableListOf<String>()
+ private var display = listOf<String>()
private var profileId = ""
private var lastLeaderboardUpdate = 0L
private var apiError = false
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt
index 2205d9c8e..cce6dd67f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt
@@ -9,11 +9,12 @@ import at.hannibal2.skyhanni.utils.TimeUtils
import java.util.*
class GardenBestCropTime {
- val display = mutableListOf<List<Any>>()
+ var display = listOf<List<Any>>()
val timeTillNextCrop = mutableMapOf<CropType, Long>()
private val config get() = SkyHanniMod.feature.garden
- fun drawBestDisplay(currentCrop: CropType?) {
+ fun drawBestDisplay(currentCrop: CropType?): List<List<Any>> {
+ val newList = mutableListOf<List<Any>>()
if (timeTillNextCrop.size < CropType.values().size) {
updateTimeTillNextCrop()
}
@@ -33,10 +34,11 @@ class GardenBestCropTime {
}
val title = if (gardenExp) "§2Garden Experience" else "§bSkyBlock Level"
- display.add(Collections.singletonList("§eBest Crop Time §7($title§7)"))
+ newList.add(Collections.singletonList("§eBest Crop Time §7($title§7)"))
if (sorted.isEmpty()) {
- display.add(Collections.singletonList("§cFarm crops to add them to this list!"))
+ newList.add(Collections.singletonList("§cFarm crops to add them to this list!"))
+ return newList
}
var number = 0
@@ -61,8 +63,9 @@ class GardenBestCropTime {
val gardenExpForTier = getGardenExpForTier(nextTier)
list.add(" §7(§2$gardenExpForTier §7Exp)")
}
- display.add(list)
+ newList.add(list)
}
+ return newList
}
private fun getGardenExpForTier(gardenLevel: Int) = if (gardenLevel > 30) 300 else gardenLevel * 10
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
index 89461e076..eb8bcde86 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
@@ -19,7 +19,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.*
class GardenCropMilestoneDisplay {
- private val progressDisplay = mutableListOf<List<Any>>()
+ private var progressDisplay = listOf<List<Any>>()
private val cultivatingData = mutableMapOf<CropType, Int>()
private val config get() = SkyHanniMod.feature.garden
private val bestCropTime = GardenBestCropTime()
@@ -147,28 +147,29 @@ class GardenCropMilestoneDisplay {
}
private fun update() {
- progressDisplay.clear()
- bestCropTime.display.clear()
+ progressDisplay = emptyList()
+ bestCropTime.display = emptyList()
currentCrop?.let {
- drawProgressDisplay(it, it.getCounter())
+ progressDisplay = drawProgressDisplay(it, it.getCounter())
if (config.cropMilestoneBestDisplay) {
- bestCropTime.drawBestDisplay(it)
+ bestCropTime.display = bestCropTime.drawBestDisplay(it)
}
}
if (config.cropMilestoneBestAlwaysOn) {
if (currentCrop == null) {
- bestCropTime.drawBestDisplay(null)
+ bestCropTime.display = bestCropTime.drawBestDisplay(null)
}
}
}
- private fun drawProgressDisplay(crop: CropType, counter: Long) {
- progressDisplay.add(Collections.singletonList("§6Crop Milestones"))
+ private fun drawProgressDisplay(crop: CropType, counter: Long): MutableList<List<Any>> {
+ val newList = mutableListOf<List<Any>>()
+ newList.add(Collections.singletonList("§6Crop Milestones"))
val list = mutableListOf<Any>()
GardenAPI.addGardenCropToList(crop, list)
list.add(crop.cropName)
- progressDisplay.add(list)
+ newList.add(list)
val currentTier = GardenCropMilestones.getTierForCrops(counter)
@@ -181,13 +182,13 @@ class GardenCropMilestoneDisplay {
val haveFormat = LorenzUtils.formatInteger(have)
val needFormat = LorenzUtils.formatInteger(need)
- progressDisplay.add(Collections.singletonList("§7Progress to Tier $nextTier§8:"))
- progressDisplay.add(Collections.singletonList("§e$haveFormat§8/§e$needFormat"))
+ newList.add(Collections.singletonList("§7Progress to Tier $nextTier§8:"))
+ newList.add(Collections.singletonList("§e$haveFormat§8/§e$needFormat"))
lastItemInHand?.let {
if (GardenAPI.readCounter(it) == -1) {
- progressDisplay.add(Collections.singletonList("§cWarning: You need Cultivating!"))
- return
+ newList.add(Collections.singletonList("§cWarning: You need Cultivating!"))
+ return newList
}
}
@@ -207,15 +208,17 @@ class GardenCropMilestoneDisplay {
SendTitleHelper.sendTitle("§b$crop $nextTier in $duration", 1_500)
}
}
- progressDisplay.add(Collections.singletonList("§7in §b$duration"))
+ newList.add(Collections.singletonList("§7in §b$duration"))
val format = LorenzUtils.formatInteger(averageSpeedPerSecond * 60)
- progressDisplay.add(Collections.singletonList("§7Crops/minute§8: §e$format"))
+ newList.add(Collections.singletonList("§7Crops/minute§8: §e$format"))
}
if (needsInventory) {
- progressDisplay.add(Collections.singletonList("§cOpen §e/cropmilestones §cto update!"))
+ newList.add(Collections.singletonList("§cOpen §e/cropmilestones §cto update!"))
}
+
+ return newList
}
private fun isEnabled() = GardenAPI.inGarden() && config.cropMilestoneProgress
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt
index d01716ea0..5be04363c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt
@@ -17,7 +17,7 @@ import java.time.Instant
import java.util.regex.Pattern
class GardenNextJacobContest {
- private val display = mutableListOf<Any>()
+ private var display = listOf<Any>()
private var tick = 0
private var contests = mutableMapOf<Long, FarmingContest>()
private var inCalendar = false
@@ -121,9 +121,7 @@ class GardenNextJacobContest {
private fun update() {
nextContestCrops.clear()
- val newDisplay = drawDisplay()
- display.clear()
- display.addAll(newDisplay)
+ display = drawDisplay()
}
private fun drawDisplay(): List<Any> {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt
index f66697e6a..1e0be2855 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt
@@ -30,7 +30,7 @@ import java.util.regex.Pattern
class GardenVisitorFeatures {
private val visitors = mutableMapOf<String, Visitor>()
- private val display = mutableListOf<List<Any>>()
+ private var display = listOf<List<Any>>()
private var lastClickedNpc = 0
private var onBarnPlot = false
private var tick = 0
@@ -88,9 +88,7 @@ class GardenVisitorFeatures {
}
private fun updateDisplay() {
- val list = drawDisplay()
- display.clear()
- display.addAll(list)
+ display = drawDisplay()
}
private fun drawDisplay(): List<List<Any>> {
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt
index d1d9119cd..d38e9f3b3 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt
@@ -21,7 +21,7 @@ import java.util.regex.Pattern
class SkyMartBestProfit {
private val pattern = Pattern.compile("§c(.*) Copper")
- private val display = mutableListOf<List<Any>>()
+ private var display = listOf<List<Any>>()
private val config get() = SkyHanniMod.feature.garden
@SubscribeEvent
@@ -63,10 +63,17 @@ class SkyMartBestProfit {
}
}
- display.clear()
+ display = drawDisplay(priceMap, iconMap)
+ }
+
+ private fun drawDisplay(
+ priceMap: MutableMap<Pair<String, String>, Double>,
+ iconMap: MutableMap<String, ItemStack>,
+ ): MutableList<List<Any>> {
+ val newList = mutableListOf<List<Any>>()
- display.add(Collections.singletonList("Coins per §cCopper§f:"))
- display.add(Collections.singletonList(""))
+ newList.add(Collections.singletonList("Coins per §cCopper§f:"))
+ newList.add(Collections.singletonList(""))
val keys = priceMap.sortedDesc().keys
val renderer = Minecraft.getMinecraft().fontRendererObj
@@ -78,13 +85,14 @@ class SkyMartBestProfit {
while (renderer.getStringWidth(displayName.removeColor()) < longest) {
displayName += " "
}
- display.add(listOf(itemStack, "$displayName $second"))
+ newList.add(listOf(itemStack, "$displayName $second"))
}
+ return newList
}
@SubscribeEvent
fun onInventoryClose(event: InventoryCloseEvent) {
- display.clear()
+ display = emptyList()
}
@SubscribeEvent