From 8f8df60eb5f8bc69eb76b385f4298d29ca8ca649 Mon Sep 17 00:00:00 2001 From: efefury <69400149+efefury@users.noreply.github.com> Date: Wed, 12 Apr 2023 21:12:22 +0000 Subject: added notification when organic matter/fuel is low in composter (#40) --- .../hannibal2/skyhanni/config/features/Garden.java | 45 ++++++++++++++++++++-- .../hannibal2/skyhanni/config/features/Hidden.java | 6 +++ .../at/hannibal2/skyhanni/data/SkillExperience.kt | 13 +------ .../skyhanni/features/garden/ComposterDisplay.kt | 38 +++++++++++++++++- .../java/at/hannibal2/skyhanni/utils/NumberUtil.kt | 13 +++++++ 5 files changed, 98 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java index 4ac5450ba..6fbe69ad2 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -745,9 +745,6 @@ public class Garden { @ConfigAccordionId(id = 17) public boolean composterHighLightUpgrade = true; - @Expose - public Position composterDisplayPos = new Position(-363, 13, false, true); - @Expose @ConfigOption( name = "Inventory Numbers", @@ -757,6 +754,47 @@ public class Garden { @ConfigAccordionId(id = 17) public boolean composterInventoryNumbers = true; + @Expose + @ConfigOption(name = "Notification When Low Composter", desc = "") + @ConfigAccordionId(id = 17) + @ConfigEditorAccordion(id = 21) + public boolean composterNotifyLow = false; + + @Expose + @ConfigOption(name = "Enable", desc = "Show a notification when organic matter or fuel runs low in your composter.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 21) + public boolean composterNotifyLowEnabled = true; + + @Expose + @ConfigOption(name = "Show Title", desc = "Send a title to notify.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 21) + public boolean composterNotifyLowTitle = false; + + @Expose + @ConfigOption(name = "Min Organic Matter", desc = "Warn when Organic Matter is below this value.") + @ConfigEditorSlider( + minValue = 1_000, + maxValue = 80_000, + minStep = 1 + ) + @ConfigAccordionId(id = 21) + public int composterNotifyLowOrganicMatter = 20_000; + + @Expose + @ConfigOption(name = "Min Fuel Cap", desc = "Warn when Fuel is below this value.") + @ConfigEditorSlider( + minValue = 500, + maxValue = 40_000, + minStep = 1 + ) + @ConfigAccordionId(id = 21) + public int composterNotifyLowFuel = 10_000; + + @Expose + public Position composterDisplayPos = new Position(-363, 13, false, true); + @Expose @ConfigOption(name = "True Farming Fortune", desc = "") @ConfigEditorAccordion(id = 18) @@ -828,6 +866,7 @@ public class Garden { @ConfigEditorBoolean public boolean deskInSkyBlockMenu = true; + @Expose @ConfigOption(name = "Fungi Cutter Warning", desc = "Warn when breaking mushroom with the wrong Fungi Cutter mode.") @ConfigEditorBoolean 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 59133d122..4638f816d 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java @@ -53,6 +53,12 @@ public class Hidden { @Expose public Map gardenDicerRngDrops = new HashMap<>(); + @Expose + public long informedAboutLowMatter = 0; + + @Expose + public long informedAboutLowFuel = 0; + @Expose public Map> gardenJacobFarmingContestTimes = new HashMap<>(); diff --git a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt index e80551dec..d910a26bc 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SkillExperience.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -182,15 +183,3 @@ class SkillExperience { } } -private fun String.formatNumber(): Long { - var text = replace(",", "") - val multiplier = if (text.endsWith("k")) { - text = text.substring(0, text.length - 1) - 1_000 - } else if (text.endsWith("m")) { - text = text.substring(0, text.length - 1) - 1_000_000 - } else 1 - val d = text.toDouble() - return (d * multiplier).toLong() -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt index 7f37c6867..23316166f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt @@ -1,24 +1,28 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.SendTitleHelper import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent +import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.util.regex.Pattern class ComposterDisplay { private val config get() = SkyHanniMod.feature.garden + private val hidden get() = SkyHanniMod.feature.hidden private var display = listOf>() enum class DataType(val pattern: String, val icon: String) { ORGANIC_MATTER(" Organic Matter: §r(.*)", "WHEAT"), FUEL(" Fuel: §r(.*)", "OIL_BARREL"), TIME_LEFT(" Time Left: §r(.*)", "WATCH"), - STORED_COMPOST(" Stored Compost: §r(.*)", "COMPOST"), - ; + STORED_COMPOST(" Stored Compost: §r(.*)", "COMPOST"); val displayItem by lazy { NEUItems.getItemStack(icon) @@ -71,6 +75,36 @@ class ComposterDisplay { newList.add(DataType.STORED_COMPOST.addToList(data)) display = newList + + notify(data) + } + + private fun notify(data: MutableMap) { + if (!config.composterNotifyLowEnabled) return + + data[DataType.ORGANIC_MATTER]?.removeColor()?.formatNumber()?.let { + if (it <= config.composterNotifyLowOrganicMatter) { + if (System.currentTimeMillis() >= hidden.informedAboutLowMatter) { + if (config.composterNotifyLowTitle) { + SendTitleHelper.sendTitle("§cYour Organic Matter is low", 4_000) + } + LorenzUtils.chat("§e[SkyHanni] §cYour Organic Matter is low!") + hidden.informedAboutLowMatter = System.currentTimeMillis() + 30_000 + } + } + } + + data[DataType.FUEL]?.removeColor()?.formatNumber()?.let { + if (it <= config.composterNotifyLowFuel && + System.currentTimeMillis() >= hidden.informedAboutLowFuel + ) { + if (config.composterNotifyLowTitle) { + SendTitleHelper.sendTitle("§cYour Fuel is low", 4_000) + } + LorenzUtils.chat("§e[SkyHanni] §cYour Fuel is low!") + hidden.informedAboutLowFuel = System.currentTimeMillis() + 30_000 + } + } } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt index a3c86c0f4..0d09ea81d 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt @@ -177,4 +177,17 @@ object NumberUtil { else -> LorenzColor.RED } } + + fun String.formatNumber(): Long { + var text = replace(",", "") + val multiplier = if (text.endsWith("k")) { + text = text.substring(0, text.length - 1) + 1_000 + } else if (text.endsWith("m")) { + text = text.substring(0, text.length - 1) + 1_000_000 + } else 1 + val d = text.toDouble() + return (d * multiplier).toLong() + } } \ No newline at end of file -- cgit