diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-19 14:07:29 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-19 14:07:29 +0100 |
commit | 1eb058d6800f9e01ac7c7696254ef955e60c80c4 (patch) | |
tree | 5446996b2435470f209892d321f43cd24ee45bb6 /src/main/java/at | |
parent | 25b6fe99c4d03c565bc8cb024c4b6e232203614d (diff) | |
download | skyhanni-1eb058d6800f9e01ac7c7696254ef955e60c80c4.tar.gz skyhanni-1eb058d6800f9e01ac7c7696254ef955e60c80c4.tar.bz2 skyhanni-1eb058d6800f9e01ac7c7696254ef955e60c80c4.zip |
Added config for farming contest timer
Diffstat (limited to 'src/main/java/at')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java | 3 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt | 36 |
2 files changed, 26 insertions, 13 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java index 547c4a24d..e3502a122 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java @@ -44,4 +44,7 @@ public class Hidden { @Expose public Map<String, Integer> gardenDicerRngDrops = new HashMap<>(); + + @Expose + public Map<Long, List<String>> gardenJacobFarmingContestTimes = new HashMap<>(); } 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 193efecc6..b2edd442d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryOpenEvent @@ -21,6 +22,9 @@ class GardenNextJacobContest { private var tick = 0 private var contests = mutableMapOf<Long, FarmingContest>() private var inCalendar = false + private val patternDay = Pattern.compile("§aDay (.*)") + private val patternMonth = Pattern.compile("(.*), Year (.*)") + private val patternCrop = Pattern.compile("§e○ §7(.*)") private val maxContestsPerYear = 124 private val contestDuration = 1_000 * 60 * 20 @@ -60,10 +64,9 @@ class GardenNextJacobContest { private fun readCalendar(event: InventoryOpenEvent) { val inventoryName = event.inventoryName - val patternMonth = Pattern.compile("(.*), Year (.*)") val matcher = patternMonth.matcher(inventoryName) if (!matcher.matches()) return - val rawMonth = matcher.group(1) + val month = LorenzUtils.getSBMonthByName(matcher.group(1)) val year = matcher.group(2).toInt() if (contests.isNotEmpty()) { @@ -76,11 +79,6 @@ class GardenNextJacobContest { } } - - val month = LorenzUtils.getSBMonthByName(rawMonth) - - val patternDay = Pattern.compile("§aDay (.*)") - val patternCrop = Pattern.compile("§e○ §7(.*)") for (item in event.inventoryItems.values) { val lore = item.getLore() if (!lore.any { it.contains("§6§eJacob's Farming Contest") }) continue @@ -90,22 +88,34 @@ class GardenNextJacobContest { if (!matcherDay.matches()) continue val day = matcherDay.group(1).toInt() - - val sbTime = SkyBlockTime(year, month, day) - val startTime = sbTime.toMillis() + val startTime = SkyBlockTime(year, month, day).toMillis() val crops = mutableListOf<String>() for (line in lore) { val matcherCrop = patternCrop.matcher(line) if (!matcherCrop.matches()) continue - - val crop = matcherCrop.group(1) - crops.add(crop) + crops.add(matcherCrop.group(1)) } val contest = FarmingContest(startTime + contestDuration, crops) contests[startTime] = contest } update() + saveConfig() + } + + private fun saveConfig() { + val map = SkyHanniMod.feature.hidden.gardenJacobFarmingContestTimes + map.clear() + for (contest in contests.values) { + map[contest.endTime] = contest.crops + } + } + + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + for ((time, crops) in SkyHanniMod.feature.hidden.gardenJacobFarmingContestTimes) { + contests[time] = FarmingContest(time, crops) + } } class FarmingContest(val endTime: Long, val crops: List<String>) |