diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-18 00:27:01 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-18 00:27:01 +0200 |
commit | a10c097974d0b476be275c1fd2888d7502508efd (patch) | |
tree | b9059f9ff1d010ce7ee32c4aece25a5dbc4141c3 /src/main/java/at/hannibal2/skyhanni/features/garden | |
parent | 88bff6a920bd597e7ef2a22bbcd99750158e6816 (diff) | |
download | skyhanni-a10c097974d0b476be275c1fd2888d7502508efd.tar.gz skyhanni-a10c097974d0b476be275c1fd2888d7502508efd.tar.bz2 skyhanni-a10c097974d0b476be275c1fd2888d7502508efd.zip |
added profile specific config support
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
18 files changed, 153 insertions, 104 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt index 65b92f8d2..9159c18ee 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt @@ -34,6 +34,12 @@ class FarmingFortuneDisplay { private var ticks: Int = 0 @SubscribeEvent + fun onPreProfileSwitch(event: PreProfileSwitchEvent) { + display = emptyList() + accessoryProgressDisplay = "" + } + + @SubscribeEvent fun onTabListUpdate(event: TabListUpdateEvent) { if (!GardenAPI.inGarden()) return tabFortune = event.tabList.firstNotNullOfOrNull { @@ -52,7 +58,6 @@ class FarmingFortuneDisplay { fun onBlockBreak(event: CropClickEvent) { val cropBroken = event.crop if (cropBroken != currentCrop) { - currentCrop = cropBroken updateToolFortune(event.itemInHand) } } @@ -60,9 +65,7 @@ class FarmingFortuneDisplay { @SubscribeEvent fun onGardenToolChange(event: GardenToolChangeEvent) { lastToolSwitch = System.currentTimeMillis() - val heldTool = event.toolItem - currentCrop = event.crop ?: currentCrop - updateToolFortune(heldTool) + updateToolFortune(event.toolItem) } @SubscribeEvent @@ -96,7 +99,7 @@ class FarmingFortuneDisplay { } else "?" ) if (GardenAPI.toolInHand != null) { - latestTrueFarmingFortune[displayCrop] = getCurrentFarmingFortune(true) + latestFF?.put(displayCrop, getCurrentFarmingFortune(true)) } }) @@ -130,10 +133,9 @@ class FarmingFortuneDisplay { companion object { private val config get() = SkyHanniMod.feature.garden - private val hidden get() = SkyHanniMod.feature.hidden - private val latestTrueFarmingFortune: MutableMap<CropType, Double> get() = hidden.gardenLatestTrueFarmingFortune + private val latestFF: MutableMap<CropType, Double>? get() = GardenAPI.config?.latestTrueFarmingFortune - private var currentCrop: CropType? = null + private val currentCrop get() = GardenAPI.getCurrentlyFarmedCrop() private var tabFortune: Double = 0.0 private var toolFortune: Double = 0.0 @@ -196,6 +198,6 @@ class FarmingFortuneDisplay { return baseFortune + upgradeFortune + tabFortune + toolFortune + accessoryFortune } - fun CropType.getLatestTrueFarmingFortune() = latestTrueFarmingFortune[this] + fun CropType.getLatestTrueFarmingFortune() = latestFF?.get(this) } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt index 2eb6e4fee..f5d6b7943 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.events.* import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType @@ -9,7 +10,6 @@ import at.hannibal2.skyhanni.features.garden.composter.ComposterOverlay import at.hannibal2.skyhanni.features.garden.contest.FarmingContestAPI import at.hannibal2.skyhanni.features.garden.farming.GardenBestCropTime import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed -import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.setSpeed import at.hannibal2.skyhanni.features.garden.inventory.SkyMartCopperPrice import at.hannibal2.skyhanni.utils.BlockUtils.isBabyCrop import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName @@ -36,6 +36,7 @@ object GardenAPI { var mushroomCowPet = false var inBarn = false val onBarnPlot get() = inBarn && inGarden() + val config get() = ProfileStorageData.profileSpecific?.garden var tick = 0 @@ -143,14 +144,17 @@ object GardenAPI { SkyMartCopperPrice.inInventory || FarmingContestAPI.inInventory fun clearCropSpeed() { - for (type in CropType.values()) { - type.setSpeed(-1) - } + config?.cropsPerSecond?.clear() GardenBestCropTime.reset() updateGardenTool() LorenzUtils.chat("§e[SkyHanni] Manually reset all crop speed data!") } + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + GardenBestCropTime.reset() + } + fun getCurrentlyFarmedCrop(): CropType? { val brokenCrop = if (toolInHand != null) GardenCropSpeed.lastBrokenCrop else null return cropInHand ?: brokenCrop 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 8fdec3787..b643e5771 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneFix.kt @@ -3,6 +3,7 @@ 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.data.ProfileStorageData import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent import at.hannibal2.skyhanni.features.garden.farming.GardenCropMilestoneDisplay @@ -47,6 +48,7 @@ class GardenCropMilestoneFix { } private fun check(cropName: String, tier: Int, percentage: Double) { + if (!ProfileStorageData.loaded) return val baseCrops = GardenCropMilestones.getCropsForTier(tier) val next = GardenCropMilestones.getCropsForTier(tier + 1) val progressCrops = next - baseCrops diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt index 4ee33e2b4..8f26863e9 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenLevelDisplay.kt @@ -21,9 +21,9 @@ class GardenLevelDisplay { private val overflowPattern = ".*§r §6(?<overflow>.*) XP".toPattern() private val namePattern = "Garden Level (?<currentLevel>.*)".toPattern() private var gardenExp - get() = SkyHanniMod.feature.hidden.gardenExp + get() = GardenAPI.config?.experience ?: -1 set(value) { - SkyHanniMod.feature.hidden.gardenExp = value + GardenAPI.config?.experience = value } private var display = "" private var visitorRewardPattern = " {4}§r§8\\+§r§2(?<exp>.*) §r§7Garden Experience".toPattern() 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 10ecc6df0..7feaf7ca4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt @@ -139,7 +139,7 @@ class GardenNextJacobContest { } private fun saveConfig() { - val map = SkyHanniMod.feature.hidden.gardenJacobFarmingContestTimes + val map = SkyHanniMod.feature.storage.gardenJacobFarmingContestTimes map.clear() for (contest in contests.values) { map[contest.endTime] = contest.crops @@ -148,7 +148,7 @@ class GardenNextJacobContest { @SubscribeEvent fun onConfigLoad(event: ConfigLoadEvent) { - for ((time, crops) in SkyHanniMod.feature.hidden.gardenJacobFarmingContestTimes) { + for ((time, crops) in SkyHanniMod.feature.storage.gardenJacobFarmingContestTimes) { contests[time] = FarmingContest(time, crops) } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt index 73cdce3ad..5c3e6d433 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt @@ -1,7 +1,6 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.GardenCropMilestones import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.features.garden.GardenAPI.getCropType import at.hannibal2.skyhanni.utils.LorenzUtils @@ -24,10 +23,6 @@ class ToolTooltipTweaks { @SubscribeEvent fun onTooltip(event: LorenzToolTipEvent) { if (!LorenzUtils.inSkyBlock) return - if (GardenCropMilestones.cropCounter.isEmpty()) { - LorenzUtils.debug("Garden ToolTip Tweaks: crop counter data not yet loaded!") - return - } val crop = event.itemStack.getCropType() ?: return val toolFortune = FarmingFortuneDisplay.getToolFortune(event.itemStack) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterAPI.kt index fb45d179c..3a22e5d39 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterAPI.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.features.garden.composter -import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.model.ComposterUpgrade +import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.StringUtils.removeColor import kotlin.time.Duration @@ -9,9 +9,9 @@ import kotlin.time.Duration.Companion.minutes object ComposterAPI { var tabListData = mapOf<ComposterDisplay.DataType, String>() - val composterUpgrades: MutableMap<ComposterUpgrade, Int> get() = SkyHanniMod.feature.hidden.gardenComposterUpgrades + val composterUpgrades: MutableMap<ComposterUpgrade, Int>? get() = GardenAPI.config?.composterUpgrades - fun ComposterUpgrade.getLevel(addOne: ComposterUpgrade?) = (composterUpgrades[this] ?: 0) + if (addOne == this) 1 else 0 + fun ComposterUpgrade.getLevel(addOne: ComposterUpgrade?) = (composterUpgrades?.get(this) ?: 0) + if (addOne == this) 1 else 0 fun getFuel() = tabListData[ComposterDisplay.DataType.FUEL]?.removeColor()?.formatNumber() ?: 0 diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt index 763186a03..8f6a34a18 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt @@ -17,7 +17,7 @@ import kotlin.time.DurationUnit class ComposterDisplay { private val config get() = SkyHanniMod.feature.garden - private val hidden get() = SkyHanniMod.feature.hidden + private val hidden get() = GardenAPI.config private var display = listOf<List<Any>>() private var composterEmptyTime: Duration? = null @@ -33,7 +33,7 @@ class ComposterDisplay { NEUItems.getItemStack(icon) } - val pattern by lazy {rawPattern.toPattern()} + val pattern by lazy { rawPattern.toPattern() } fun addToList(map: Map<DataType, String>): List<Any> { return listOf(displayItem, map[this]!!) @@ -57,7 +57,7 @@ class ComposterDisplay { val organicMatter = ComposterAPI.getOrganicMatter() val fuel = ComposterAPI.getFuel() - if (ComposterAPI.composterUpgrades.isEmpty()) { + if (ComposterAPI.composterUpgrades.isNullOrEmpty()) { composterEmptyTime = null return } @@ -135,6 +135,7 @@ class ComposterDisplay { private fun sendNotify() { if (!config.composterNotifyLowEnabled) return + val hidden = hidden ?: return if (ComposterAPI.getOrganicMatter() <= config.composterNotifyLowOrganicMatter) { if (System.currentTimeMillis() >= hidden.informedAboutLowMatter) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt index 1e027b6ab..7616ee323 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt @@ -49,17 +49,16 @@ class ComposterOverlay { private var lastHovered = 0L companion object { - private val hidden get() = SkyHanniMod.feature.hidden - var currentOrganicMatterItem: String - get() = hidden.gardenComposterCurrentOrganicMatterItem + var currentOrganicMatterItem: String? + get() = GardenAPI.config?.composterCurrentOrganicMatterItem private set(value) { - hidden.gardenComposterCurrentOrganicMatterItem = value + GardenAPI.config?.composterCurrentOrganicMatterItem = value } - var currentFuelItem: String - get() = hidden.gardenComposterCurrentFuelItem + var currentFuelItem: String? + get() = GardenAPI.config?.composterCurrentFuelItem private set(value) { - hidden.gardenComposterCurrentFuelItem = value + GardenAPI.config?.composterCurrentFuelItem = value } var testOffset = 0 @@ -270,8 +269,8 @@ class ComposterOverlay { } private fun addExtraData(newList: MutableList<List<Any>>) { - val organicMatterItem = currentOrganicMatterItem - val fuelItem = currentFuelItem + val organicMatterItem = currentOrganicMatterItem ?: return + val fuelItem = currentFuelItem ?: return if (organicMatterItem == "" || fuelItem == "") return newList.addSelector("§7Per ", TimeType.values(), diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt index 4c6bb23f8..aedcab012 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.features.garden.farming import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.GardenToolChangeEvent import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.PreProfileSwitchEvent import at.hannibal2.skyhanni.features.bazaar.BazaarApi import at.hannibal2.skyhanni.features.bazaar.BazaarData import at.hannibal2.skyhanni.features.garden.CropType @@ -43,7 +44,12 @@ object CropMoneyDisplay { private var loaded = false private var ready = false private val cropNames = mutableMapOf<String, CropType>() // internalName -> cropName - private val toolHasBountiful: MutableMap<CropType, Boolean> get() = SkyHanniMod.feature.hidden.gardenToolHasBountiful + private val toolHasBountiful get() = GardenAPI.config?.toolWithBountiful + + @SubscribeEvent + fun onPreProfileSwitch(event: PreProfileSwitchEvent) { + display = emptyList() + } @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { @@ -102,7 +108,7 @@ object CropMoneyDisplay { var extraNetherWartPrices = 0.0 GardenAPI.getCurrentlyFarmedCrop()?.let { val reforgeName = Minecraft.getMinecraft().thePlayer.heldItem?.getReforgeName() - toolHasBountiful[it] = reforgeName == "bountiful" + toolHasBountiful?.put(it, reforgeName == "bountiful") if (GardenAPI.mushroomCowPet && it != CropType.MUSHROOM) { val redPrice = NEUItems.getPrice("ENCHANTED_RED_MUSHROOM") / 160 @@ -301,7 +307,7 @@ object CropMoneyDisplay { } } - val bountifulMoney = if (toolHasBountiful[crop] == true) speedPerHour * 0.2 else 0.0 + val bountifulMoney = if (toolHasBountiful?.get(crop) == true) speedPerHour * 0.2 else 0.0 moneyPerHours[internalName] = formatNumbers(sellOffer + bountifulMoney, instantSell + bountifulMoney, npcPrice + bountifulMoney) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt index ca15c038a..ad9ad9737 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/DicerRngDropCounter.kt @@ -1,10 +1,7 @@ package at.hannibal2.skyhanni.features.garden.farming import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.ConfigLoadEvent -import at.hannibal2.skyhanni.events.GardenToolChangeEvent -import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.* import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.ItemUtils.name @@ -20,8 +17,7 @@ class DicerRngDropCounter { private val config get() = SkyHanniMod.feature.garden init { - drops[CropType.MELON] = mutableMapOf() - drops[CropType.PUMPKIN] = mutableMapOf() + initDrops() itemDrops.add(ItemDrop(CropType.MELON, DropRarity.UNCOMMON, "§a§lUNCOMMON DROP! §r§eDicer dropped §r§a1x §r§aEnchanted Melon§r§e!")) itemDrops.add(ItemDrop(CropType.MELON, DropRarity.RARE, "§9§lRARE DROP! §r§eDicer dropped §r§a5x §r§aEnchanted Melon§r§e!")) @@ -34,6 +30,11 @@ class DicerRngDropCounter { itemDrops.add(ItemDrop(CropType.PUMPKIN, DropRarity.PRAY_TO_RNGESUS, "§5§lPRAY TO RNGESUS DROP! §r§eDicer dropped §r§a64x §r§aEnchanted Pumpkin§r§e!")) } + private fun initDrops() { + drops[CropType.MELON] = mutableMapOf() + drops[CropType.PUMPKIN] = mutableMapOf() + } + enum class DropRarity(val displayName: String) { UNCOMMON("§a§lUNCOMMON DROP"), RARE("§9§lRARE DROP"), @@ -42,6 +43,13 @@ class DicerRngDropCounter { } @SubscribeEvent + fun onPreProfileSwitch(event: PreProfileSwitchEvent) { + display = emptyList() + drops.clear() + initDrops() + } + + @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!isEnabled()) return @@ -104,7 +112,7 @@ class DicerRngDropCounter { class ItemDrop(val crop: CropType, val rarity: DropRarity, val message: String) private fun saveConfig() { - val map = SkyHanniMod.feature.hidden.gardenDicerRngDrops + val map = GardenAPI.config?.dicerRngDrops ?: return map.clear() for (drop in drops) { val crop = drop.key @@ -116,7 +124,8 @@ class DicerRngDropCounter { @SubscribeEvent fun onConfigLoad(event: ConfigLoadEvent) { - for ((internalName, amount) in SkyHanniMod.feature.hidden.gardenDicerRngDrops) { + val map = GardenAPI.config?.dicerRngDrops ?: return + for ((internalName, amount) in map) { val split = internalName.split(".") val crop = CropType.getByName(split[0]) val rarityName = split[1] diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/EliteFarmingWeight.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/EliteFarmingWeight.kt index a71edb381..37c92258e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/EliteFarmingWeight.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/EliteFarmingWeight.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.events.GardenToolChangeEvent import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.PreProfileSwitchEvent import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.getSpeed @@ -49,6 +50,15 @@ class EliteFarmingWeight { nextPlayerWeight = 0.0 nextPlayerName = "" hasPassedNext = false + localCounter.clear() + } + + @SubscribeEvent + fun onPreProfileSwitch(event: PreProfileSwitchEvent) { + display = emptyList() + profileId = "" + weight = -2.0 + } var tick = 0 diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingArmorDrops.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingArmorDrops.kt index 2423f1a62..f9ad49e17 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingArmorDrops.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/FarmingArmorDrops.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.PreProfileSwitchEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName @@ -28,6 +29,13 @@ class FarmingArmorDrops { } @SubscribeEvent + fun onPreProfileSwitch(event: PreProfileSwitchEvent) { + display = emptyList() + drops.clear() + hasArmor = false + } + + @SubscribeEvent fun onChat(event: LorenzChatEvent) { for (dropType in ArmorDropType.values()) { if (dropType.chatMessage == event.message) { @@ -62,7 +70,7 @@ class FarmingArmorDrops { } private fun saveConfig() { - val map = SkyHanniMod.feature.hidden.gardenFarmingArmorDrops + val map = GardenAPI.config?.farmArmorDrops ?: return map.clear() for ((drop, amount) in drops) { map[drop.toString()] = amount @@ -71,7 +79,8 @@ class FarmingArmorDrops { @SubscribeEvent fun onConfigLoad(event: ConfigLoadEvent) { - for ((rawName, amount) in SkyHanniMod.feature.hidden.gardenFarmingArmorDrops) { + val map = GardenAPI.config?.farmArmorDrops ?: return + for ((rawName, amount) in map) { drops[ArmorDropType.valueOf(rawName)] = amount } update() 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 de8d299fd..5d98bd05d 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 @@ -11,7 +11,6 @@ import at.hannibal2.skyhanni.features.garden.FarmingFortuneDisplay import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.GardenAPI.addCropIcon import at.hannibal2.skyhanni.features.garden.GardenAPI.getCropType -import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.isSpeedDataEmpty import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.setSpeed import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList @@ -78,8 +77,10 @@ object GardenCropMilestoneDisplay { @SubscribeEvent(priority = EventPriority.LOW) fun onProfileJoin(event: ProfileJoinEvent) { - if (GardenCropMilestones.cropCounter.values.sum() == 0L) { - needsInventory = true + GardenCropMilestones.cropCounter?.let { + if (it.values.sum() == 0L) { + needsInventory = true + } } } @@ -102,17 +103,6 @@ object GardenCropMilestoneDisplay { if (cultivatingData.containsKey(crop)) { val old = cultivatingData[crop]!! val addedCounter = (counter - old).toInt() - - if (GardenCropMilestones.cropCounter.isEmpty()) { - for (innerCrop in CropType.values()) { - innerCrop.setCounter(0) - } - } - if (isSpeedDataEmpty()) { - for (cropType in CropType.values()) { - cropType.setSpeed(-1) - } - } EliteFarmingWeight.addCrop(crop, addedCounter) update() crop.setCounter( @@ -133,10 +123,6 @@ object GardenCropMilestoneDisplay { mushroomCowPerkDisplay = emptyList() bestCropTime.display = emptyList() val currentCrop = GardenAPI.getCurrentlyFarmedCrop() - if (GardenCropMilestones.cropCounter.isEmpty()) { - LorenzUtils.debug("Garden Crop Milestone Display: crop counter data not yet loaded!") - return - } currentCrop?.let { progressDisplay = drawProgressDisplay(it) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt index af797ba2e..3c61691ef 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCropSpeed.kt @@ -7,20 +7,19 @@ import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.setCounter import at.hannibal2.skyhanni.data.MayorElection import at.hannibal2.skyhanni.events.CropClickEvent import at.hannibal2.skyhanni.events.GardenToolChangeEvent -import at.hannibal2.skyhanni.events.ProfileJoinEvent +import at.hannibal2.skyhanni.events.PreProfileSwitchEvent import at.hannibal2.skyhanni.features.garden.CropType import at.hannibal2.skyhanni.features.garden.GardenAPI -import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.concurrent.fixedRateTimer object GardenCropSpeed { private val config get() = SkyHanniMod.feature.garden - private val hidden get() = SkyHanniMod.feature.hidden - private val cropsPerSecond: MutableMap<CropType, Int> get() = hidden.gardenCropsPerSecond - private val latestBlocksPerSecond: MutableMap<CropType, Double> get() = hidden.gardenLatestBlocksPerSecond + private val cropsPerSecond: MutableMap<CropType, Int>? get() = GardenAPI.config?.cropsPerSecond + private val latestBlocksPerSecond: MutableMap<CropType, Double>? get() = GardenAPI.config?.latestBlocksPerSecond var lastBrokenCrop: CropType? = null + var averageBlocksPerSecond = 0.0 private val blocksSpeedList = mutableListOf<Int>() @@ -41,6 +40,11 @@ object GardenCropSpeed { } @SubscribeEvent + fun onPreProfileSwitch(event: PreProfileSwitchEvent) { + lastBrokenCrop = null + } + + @SubscribeEvent fun onGardenToolChange(event: GardenToolChangeEvent) { if (isEnabled()) { resetSpeed() @@ -85,7 +89,7 @@ object GardenCropSpeed { blocksSpeedList.dropLast(1).average() } else 0.0 GardenAPI.getCurrentlyFarmedCrop()?.let { - latestBlocksPerSecond[it] = averageBlocksPerSecond + latestBlocksPerSecond?.put(it, averageBlocksPerSecond) } } } @@ -102,28 +106,15 @@ object GardenCropSpeed { return forcefullyEnabledAlwaysFinnegan || perkActive } - @SubscribeEvent(priority = EventPriority.LOW) - fun onProfileJoin(event: ProfileJoinEvent) { - if (cropsPerSecond.isEmpty()) { - for (cropType in CropType.values()) { - cropType.setSpeed(-1) - } - } - } - fun isEnabled() = GardenAPI.inGarden() - fun CropType.getSpeed(): Int? { - val speed = cropsPerSecond[this] - if (speed == -1) return null - return speed - } + fun CropType.getSpeed() = cropsPerSecond?.get(this) fun CropType.setSpeed(speed: Int) { - cropsPerSecond[this] = speed + cropsPerSecond?.put(this, speed) } - fun CropType.getLatestBlocksPerSecond() = latestBlocksPerSecond[this] + fun CropType.getLatestBlocksPerSecond() = latestBlocksPerSecond?.get(this) - fun isSpeedDataEmpty() = cropsPerSecond.values.sum() < 0 + fun isSpeedDataEmpty() = cropsPerSecond?.values?.sum()?.let { it == 0 } ?: true }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt index 91c36e5b9..c056a8eb4 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorDropStatistics.kt @@ -1,8 +1,10 @@ package at.hannibal2.skyhanni.features.garden.visitor import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.PreProfileSwitchEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy @@ -13,12 +15,10 @@ import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent object GardenVisitorDropStatistics { private val config get() = SkyHanniMod.feature.garden.visitorDropsStatistics - private val hidden get() = SkyHanniMod.feature.hidden.visitorDrops private var display = listOf<List<Any>>() private var acceptedVisitors = 0 @@ -43,6 +43,11 @@ object GardenVisitorDropStatistics { } @SubscribeEvent + fun onPreProfileSwitch(event: PreProfileSwitchEvent) { + display = emptyList() + } + + @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!GardenAPI.onBarnPlot) return val message = event.message.removeColor().trim() @@ -134,6 +139,7 @@ object GardenVisitorDropStatistics { fun saveAndUpdate() { if (!GardenAPI.inGarden()) return + val hidden = GardenAPI.config?.visitorDrops ?: return hidden.acceptedVisitors = acceptedVisitors hidden.deniedVisitors = deniedVisitors totalVisitors = acceptedVisitors + deniedVisitors @@ -146,7 +152,8 @@ object GardenVisitorDropStatistics { } @SubscribeEvent - fun onWorldLoad(event: WorldEvent.Load) { + fun onConfigLoad(event: ConfigLoadEvent) { + val hidden = GardenAPI.config?.visitorDrops ?: return if (hidden.visitorRarities.size == 0) { hidden.visitorRarities.add(0) hidden.visitorRarities.add(0) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index 4018f170f..4554f3845 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -55,6 +55,12 @@ class GardenVisitorFeatures { } @SubscribeEvent + fun onPreProfileSwitch(event: PreProfileSwitchEvent) { + display = emptyList() + visitors.clear() + } + + @SubscribeEvent fun onInventoryOpen(event: InventoryOpenEvent) { inVisitorInventory = false diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt index 3c64c076b..cc04a303b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.TitleUtils import at.hannibal2.skyhanni.events.CropClickEvent import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.PreProfileSwitchEvent import at.hannibal2.skyhanni.events.VisitorArrivalEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.test.command.CopyErrorCommand @@ -25,12 +26,17 @@ class GardenVisitorTimer { private var render = "" private var lastMillis = 0L private var sixthVisitorArrivalTime: Long = 0 - private var visitorJustArrived: Boolean = false - private var sixthVisitorReady: Boolean = false - private var visitorInterval - get() = SkyHanniMod.feature.hidden.visitorInterval + private var visitorJustArrived = false + private var sixthVisitorReady = false + + //TODO nea? +// private val visitorInterval by dynamic(GardenAPI::config, Storage.ProfileSpecific.GardenStorage::visitorInterval) + private var visitorInterval: Long? + get() = GardenAPI.config?.visitorInterval set(value) { - SkyHanniMod.feature.hidden.visitorInterval = value + value?.let { + GardenAPI.config?.visitorInterval = it + } } companion object { @@ -53,14 +59,25 @@ class GardenVisitorTimer { } try { GardenVisitorDropStatistics.saveAndUpdate() - } catch (_: Throwable) {} // no config yet + } catch (_: Throwable) { + } // no config yet } } + @SubscribeEvent + fun onPreProfileSwitch(event: PreProfileSwitchEvent) { + render = "" + lastMillis = 0 + sixthVisitorArrivalTime = 0 + visitorJustArrived = false + sixthVisitorReady = false + } + private fun updateVisitorDisplay() { if (!isEnabled()) return var visitorsAmount = 0 + var visitorInterval = visitorInterval ?: return var millis = visitorInterval var queueFull = false for (line in TabListData.getTabList()) { @@ -95,8 +112,9 @@ class GardenVisitorTimer { sixthVisitorReady = false } millis = sixthVisitorArrivalTime - System.currentTimeMillis() - SkyHanniMod.feature.hidden.nextSixthVisitorArrival = System.currentTimeMillis() + millis + (5 - visitorsAmount) * visitorInterval - if (isSixthVisitorEnabled() && millis < 0) { + GardenAPI.config?.nextSixthVisitorArrival = + System.currentTimeMillis() + millis + (5 - visitorsAmount) * visitorInterval + if (isSixthVisitorEnabled() && millis < 0) { visitorsAmount++ if (!sixthVisitorReady) { TitleUtils.sendTitle("§a6th Visitor Ready", 5_000) @@ -136,7 +154,9 @@ class GardenVisitorTimer { @SubscribeEvent fun onWorldLoad(event: WorldEvent.Load) { lastVisitors = -1 - sixthVisitorArrivalTime = SkyHanniMod.feature.hidden.nextSixthVisitorArrival + GardenAPI.config?.nextSixthVisitorArrival?.let { + sixthVisitorArrivalTime = it + } sixthVisitorReady = false lastMillis = sixthVisitorArrivalTime - System.currentTimeMillis() } @@ -148,7 +168,9 @@ class GardenVisitorTimer { } private fun updateSixthVisitorArrivalTime() { - sixthVisitorArrivalTime = System.currentTimeMillis() + visitorInterval + visitorInterval?.let { + sixthVisitorArrivalTime = System.currentTimeMillis() + it + } } private fun isSixthVisitorEnabled() = config.visitorTimerSixthVisitorEnabled |