diff options
Diffstat (limited to 'src/main/java/at/hannibal2')
5 files changed, 24 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) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 71ad9edf2..60062ed3c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -7,6 +7,8 @@ import at.hannibal2.skyhanni.features.dungeon.DungeonData import at.hannibal2.skyhanni.test.TestBingo import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.StringUtils.toDashlessUUID +import io.github.moulberry.moulconfig.observer.Observer +import io.github.moulberry.moulconfig.observer.Property import io.github.moulberry.notenoughupdates.mixins.AccessorGuiEditSign import io.github.moulberry.notenoughupdates.util.SkyBlockTime import net.minecraft.client.Minecraft @@ -245,4 +247,15 @@ object LorenzUtils { fun isShiftKeyDown() = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) fun isControlKeyDown() = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL) + + // MoulConfig is in Java, I don't want to downgrade this logic + fun <T> onChange(vararg properties: Property<out T>, observer: Observer<T>) { + for (property in properties) { + property.whenChanged { a, b -> observer.observeChange(a, b) } + } + } + + fun <T> onToggle(vararg properties: Property<out T>, observer: Runnable) { + onChange(*properties) { _, _ -> observer.run() } + } }
\ No newline at end of file |