aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt48
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt10
2 files changed, 35 insertions, 23 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt
index c42ab8d6f..a6895392a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt
@@ -3,26 +3,49 @@ package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.data.GardenCropMilestones
import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter
import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.setCounter
+import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.TabListUpdateEvent
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.util.regex.Pattern
class GardenCropMilestoneFix {
- private val pattern = " Milestone: §r§a(?<crop>.*) (?<tier>.*): §r§3(?<percentage>.*)%".toPattern()
+ private val tabListPattern = " Milestone: §r§a(?<crop>.*) (?<tier>.*): §r§3(?<percentage>.*)%".toPattern()
+ private val levelUpPattern = Pattern.compile(" §r§b§lGARDEN MILESTONE §3(?<crop>.*) §8(?:.*)➜§3(?<tier>.*)")
private val tabListCropProgress = mutableMapOf<CropType, Long>()
@SubscribeEvent
+ fun onChatMessage(event: LorenzChatEvent) {
+ val matcher = levelUpPattern.matcher(event.message)
+ if (!matcher.matches()) return
+
+ val cropName = matcher.group("crop")
+ val crop = CropType.getByNameOrNull(cropName)
+ if (crop == null) {
+ LorenzUtils.debug("GardenCropMilestoneFix: crop is null: '$cropName'")
+ return
+ }
+
+ val tier = matcher.group("tier").romanToDecimalIfNeeded()
+
+ val crops = GardenCropMilestones.getCropsForTier(tier)
+ changedValue(crop, crops, "level up chat message")
+ }
+
+ @SubscribeEvent
fun onTabListUpdate(event: TabListUpdateEvent) {
for (line in event.tabList) {
- val matcher = pattern.matcher(line)
+ val matcher = tabListPattern.matcher(line)
if (!matcher.matches()) continue
val tier = matcher.group("tier").toInt()
val percentage = matcher.group("percentage").toDouble()
+ val cropName = matcher.group("crop")
- check(matcher.group("crop"), tier, percentage)
+ check(cropName, tier, percentage)
return
}
}
@@ -43,25 +66,24 @@ class GardenCropMilestoneFix {
val tabListValue = baseCrops + progress - smallestPercentage
- val long = tabListValue.toLong()
-
- if (tabListCropProgress[crop] == long) return
- if (tabListCropProgress.containsKey(crop)) {
- changedValue(crop, long)
+ val newValue = tabListValue.toLong()
+ if (tabListCropProgress[crop] != newValue) {
+ if (tabListCropProgress.containsKey(crop)) {
+ changedValue(crop, newValue, "tab list")
+ }
}
-
- tabListCropProgress[crop] = long
+ tabListCropProgress[crop] = newValue
}
- private fun changedValue(crop: CropType, tabListValue: Long) {
+ private fun changedValue(crop: CropType, tabListValue: Long, source: String) {
val calculated = crop.getCounter()
val diff = calculated - tabListValue
if (diff < -5_000) {
crop.setCounter(tabListValue)
- LorenzUtils.chat("§e[SkyHanni] Loaded ${crop.cropName} milestone data from tab list!")
+ LorenzUtils.chat("§e[SkyHanni] Loaded ${crop.cropName} milestone data from $source!")
}
if (diff > 5_000) {
- LorenzUtils.debug("Fixed wrong ${crop.cropName} milestone data from tab list: ${diff.addSeparators()}")
+ LorenzUtils.debug("Fixed wrong ${crop.cropName} milestone data from $source: ${diff.addSeparators()}")
crop.setCounter(tabListValue)
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt
index fbefe574a..48947d823 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropMilestoneDisplay.kt
@@ -32,7 +32,6 @@ class GardenCropMilestoneDisplay {
private val cultivatingData = mutableMapOf<CropType, Long>()
private val config get() = SkyHanniMod.feature.garden
private val bestCropTime = GardenBestCropTime()
-// val cropMilestoneLevelUpPattern = Pattern.compile(" §r§b§lGARDEN MILESTONE §3(.*) §8XXIII➜§3(.*)")
private var lastPlaySoundTime = 0L
@@ -63,15 +62,6 @@ class GardenCropMilestoneDisplay {
if (event.message == "§a§lUNCOMMON DROP! §r§eDicer dropped §r§f64x §r§fPumpkin§r§e!") {
CropType.PUMPKIN.setCounter(CropType.PUMPKIN.getCounter() + 64)
}
-// if (config.cropMilestoneWarnClose) {
-// val matcher = cropMilestoneLevelUpPattern.matcher(event.message)
-// if (matcher.matches()) {
-// val cropType = matcher.group(1)
-// val newLevel = matcher.group(2).romanToDecimalIfNeeded()
-// LorenzUtils.debug("found milestone messsage!")
-// SendTitleHelper.sendTitle("§b$cropType $newLevel", 1_500)
-// }
-// }
}
@SubscribeEvent