diff options
author | J10a1n15 <45315647+j10a1n15@users.noreply.github.com> | 2024-08-31 21:17:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-31 21:17:56 +0200 |
commit | 31f9e29c0aa055b615d1eaaf7bca9d8d10b0ba7e (patch) | |
tree | e9f923771820da3fb21db8a0e614e5ae376720f1 /src/main/java/at/hannibal2 | |
parent | c1c3fcc963bbf79f75e33a9383431784f36bdf36 (diff) | |
download | skyhanni-31f9e29c0aa055b615d1eaaf7bca9d8d10b0ba7e.tar.gz skyhanni-31f9e29c0aa055b615d1eaaf7bca9d8d10b0ba7e.tar.bz2 skyhanni-31f9e29c0aa055b615d1eaaf7bca9d8d10b0ba7e.zip |
Feature: Last server (#2046)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2')
3 files changed, 62 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/LastServersConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/LastServersConfig.java new file mode 100644 index 000000000..8c566cfa8 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/LastServersConfig.java @@ -0,0 +1,21 @@ +package at.hannibal2.skyhanni.config.features.misc; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import com.google.gson.annotations.Expose; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; + +public class LastServersConfig { + + @Expose + @ConfigOption(name = "Enabled", desc = "Receive notifications when you rejoin a server you have previously joined.") + @ConfigEditorBoolean + @FeatureToggle + public boolean enabled = false; + + @Expose + @ConfigOption(name = "Notification Time", desc = "Get notified if you rejoin a server within the specified number of seconds.") + @ConfigEditorSlider(minValue = 5, maxValue = 300, minStep = 1) + public Integer warnTime = 60; +} diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java index 54f0c7c50..d27d3a0e3 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java @@ -113,6 +113,11 @@ public class MiscConfig { public RemindersConfig reminders = new RemindersConfig(); @Expose + @ConfigOption(name = "Last Servers", desc = "") + @Accordion + public LastServersConfig lastServers = new LastServersConfig(); + + @Expose @ConfigOption(name = "Show Outside SkyBlock", desc = "Show these features outside of SkyBlock.") @ConfigEditorDraggableList public List<OutsideSbFeature> showOutsideSB = new ArrayList<>(); diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/LastServers.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/LastServers.kt new file mode 100644 index 000000000..8a4023314 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/LastServers.kt @@ -0,0 +1,36 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.HypixelData +import at.hannibal2.skyhanni.events.SecondPassedEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.TimeUtils.format +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds + +@SkyHanniModule +object LastServers { + + private val config get() = SkyHanniMod.feature.misc.lastServers + private var lastServerId: String? = null + private val lastServers = mutableMapOf<String, SimpleTimeMark>() + + @SubscribeEvent + fun onSecondPassed(event: SecondPassedEvent) { + if (!isEnabled() || HypixelData.serverId == lastServerId) return + + val id = HypixelData.serverId ?: return + lastServers.entries.removeIf { it.value.passedSince() > config.warnTime.seconds } + lastServers[id]?.passedSince()?.let { + ChatUtils.chat("§7You already joined this server §b${it.format()}§7 ago.") + } + ChatUtils.debug("Adding $id to last servers.") + lastServers[id] = SimpleTimeMark.now() + lastServerId = id + } + + private fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled +} |