diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-01 21:14:08 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-01 21:14:08 +0200 |
commit | 62fd05099a4f0b1cbc88368f0f99cf38ef8c5875 (patch) | |
tree | 6ff07c884a423fc72ebcd6bd40f91901b3540faa /src/main/java/at/hannibal2/skyhanni/features | |
parent | 7149f4ef911349637c3a06362588cf2398c34ed7 (diff) | |
download | skyhanni-62fd05099a4f0b1cbc88368f0f99cf38ef8c5875.tar.gz skyhanni-62fd05099a4f0b1cbc88368f0f99cf38ef8c5875.tar.bz2 skyhanni-62fd05099a4f0b1cbc88368f0f99cf38ef8c5875.zip |
Using onChange and onToggle for multi config change detection
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
4 files changed, 11 insertions, 24 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ChumBucketHider.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ChumBucketHider.kt index 73281cddf..d32dcfd11 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ChumBucketHider.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ChumBucketHider.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.CheckRenderEntityEvent import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.onToggle import at.hannibal2.skyhanni.utils.getLorenzVec import net.minecraft.entity.Entity import net.minecraft.entity.item.EntityArmorStand @@ -75,10 +76,7 @@ class ChumBucketHider { @SubscribeEvent fun onConfigLoad(event: ConfigLoadEvent) { - val function: (oldValue: Boolean, newValue: Boolean) -> Unit = { _, _ -> reset() } - config.enabled.whenChanged(function) - config.hideBucket.whenChanged(function) - config.hideOwn.whenChanged(function) + onToggle(config.enabled, config.hideBucket, config.hideOwn) { HideArmor.updateArmor() } } private fun reset() { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/HideArmor.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/HideArmor.kt index 0e252b5ed..6c081f243 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/HideArmor.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/HideArmor.kt @@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.utils.LorenzUtils -import io.github.moulberry.moulconfig.observer.Observer +import at.hannibal2.skyhanni.utils.LorenzUtils.onToggle import net.minecraft.client.Minecraft import net.minecraft.client.entity.EntityOtherPlayerMP import net.minecraft.client.entity.EntityPlayerSP @@ -49,10 +49,8 @@ class HideArmor { @SubscribeEvent fun onConfigLoaded(event: ConfigLoadEvent) { - val observer = Observer<Boolean> { a, b -> updateArmor() } - SkyHanniMod.feature.misc.hideArmorEnabled.whenChanged(observer) - SkyHanniMod.feature.misc.hideArmorOwn.whenChanged(observer) - SkyHanniMod.feature.misc.hideArmorOnlyHelmet.whenChanged(observer) + val misc = SkyHanniMod.feature.misc + onToggle(misc.hideArmorEnabled, misc.hideArmorOwn, misc.hideArmorOnlyHelmet) { updateArmor() } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/MarkedPlayerManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/MarkedPlayerManager.kt index 549ff4511..3e7547660 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/MarkedPlayerManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/MarkedPlayerManager.kt @@ -65,7 +65,7 @@ class MarkedPlayerManager { @SubscribeEvent fun onConfigLoad(event: ConfigLoadEvent) { - SkyHanniMod.feature.markedPlayers.markOwnName.whenChanged { old, new -> + SkyHanniMod.feature.markedPlayers.markOwnName.whenChanged { _, new -> val name = LorenzUtils.getPlayerName() if (new) { if (!playerNamesToMark.contains(name)) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt index 7b4ded2a2..402a643d1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/discordrpc/DiscordRPCManager.kt @@ -7,11 +7,11 @@ import at.hannibal2.skyhanni.SkyHanniMod.Companion.coroutineScope import at.hannibal2.skyhanni.SkyHanniMod.Companion.feature import at.hannibal2.skyhanni.events.ConfigLoadEvent import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.onToggle import com.google.gson.JsonObject import com.jagrosh.discordipc.IPCClient import com.jagrosh.discordipc.IPCListener import com.jagrosh.discordipc.entities.RichPresence -import io.github.moulberry.moulconfig.observer.Property import kotlinx.coroutines.launch import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -80,15 +80,11 @@ class DiscordRPCManager : IPCListener { @SubscribeEvent fun onConfigLoad(event: ConfigLoadEvent) { - for (property in listOf( - config.firstLine, + onToggle(config.firstLine, config.secondLine, - config.customText, - )) { - property.whenChangedWithDifference { - if (isActive()) { - updatePresence() - } + config.customText) { + if (isActive()) { + updatePresence() } } config.enabled.whenChanged { _, new -> @@ -99,11 +95,6 @@ class DiscordRPCManager : IPCListener { } } } - - fun Property<*>.whenChangedWithDifference(run: () -> (Unit)) { - whenChanged { old, new -> if (old != new) run() } - } - fun updatePresence() { val location = LorenzUtils.skyBlockArea val discordIconKey = DiscordLocationKey.getDiscordIconKey(location) |