From 09e1f680f34ec1ad1df16afdaceb7cce58442ade Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 26 Nov 2023 13:47:39 +0100 Subject: Automatic unlocking /shmouselock when teleporting in the garden. --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 4 +- .../skyhanni/features/garden/GardenCommands.kt | 57 -------------------- .../skyhanni/features/garden/GardenWarpCommands.kt | 63 ++++++++++++++++++++++ .../skyhanni/features/misc/LockMouseLook.kt | 6 +++ 4 files changed, 71 insertions(+), 59 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/GardenCommands.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/GardenWarpCommands.kt (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index c63003f1e..8dd3640b6 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -133,12 +133,12 @@ import at.hannibal2.skyhanni.features.fishing.trophy.TrophyFishMessages import at.hannibal2.skyhanni.features.garden.AnitaMedalProfit import at.hannibal2.skyhanni.features.garden.FarmingFortuneDisplay import at.hannibal2.skyhanni.features.garden.GardenAPI -import at.hannibal2.skyhanni.features.garden.GardenCommands import at.hannibal2.skyhanni.features.garden.GardenCropMilestoneFix import at.hannibal2.skyhanni.features.garden.GardenLevelDisplay import at.hannibal2.skyhanni.features.garden.GardenNextJacobContest import at.hannibal2.skyhanni.features.garden.GardenOptimalSpeed import at.hannibal2.skyhanni.features.garden.GardenPlotBorders +import at.hannibal2.skyhanni.features.garden.GardenWarpCommands import at.hannibal2.skyhanni.features.garden.GardenYawAndPitch import at.hannibal2.skyhanni.features.garden.ToolTooltipTweaks import at.hannibal2.skyhanni.features.garden.composter.ComposterDisplay @@ -385,7 +385,7 @@ class SkyHanniMod { loadModule(ActionBarStatsData) loadModule(GardenCropMilestoneInventory()) loadModule(GardenCropSpeed) - loadModule(GardenCommands()) + loadModule(GardenWarpCommands()) loadModule(ProfileStorageData) loadModule(TitleData()) loadModule(BlockData()) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCommands.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCommands.kt deleted file mode 100644 index 3ae6b81f6..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCommands.kt +++ /dev/null @@ -1,57 +0,0 @@ -package at.hannibal2.skyhanni.features.garden - -import at.hannibal2.skyhanni.events.LorenzKeyPressEvent -import at.hannibal2.skyhanni.events.MessageSendToServerEvent -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NEUItems -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import net.minecraft.client.Minecraft -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -class GardenCommands { - private val config get() = GardenAPI.config.gardenCommands - - // TODO repo - private val tpPlotPattern = "/tp (?.*)".toPattern() - - @SubscribeEvent - fun onMessageSendToServer(event: MessageSendToServerEvent) { - if (!config.warpCommands) return - if (!GardenAPI.inGarden()) return - - val message = event.message.lowercase() - - if (message == "/home") { - event.isCanceled = true - LorenzUtils.sendCommandToServer("warp garden") - LorenzUtils.chat("§aTeleported you to the spawn location!", prefix = false) - } - - if (message == "/barn") { - event.isCanceled = true - LorenzUtils.sendCommandToServer("tptoplot barn") - } - - tpPlotPattern.matchMatcher(message) { - event.isCanceled = true - val plotName = group("plot") - LorenzUtils.sendCommandToServer("tptoplot $plotName") - } - } - - @SubscribeEvent - fun onKeyClick(event: LorenzKeyPressEvent) { - if (!GardenAPI.inGarden()) return - if (Minecraft.getMinecraft().currentScreen != null) return - if (NEUItems.neuHasFocus()) return - - val command = when (event.keyCode) { - config.homeHotkey -> "warp garden" - config.sethomeHotkey -> "sethome" - config.barnHotkey -> "tptoplot barn" - - else -> return - } - LorenzUtils.sendCommandToServer(command) - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenWarpCommands.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenWarpCommands.kt new file mode 100644 index 000000000..81b5fb2a3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenWarpCommands.kt @@ -0,0 +1,63 @@ +package at.hannibal2.skyhanni.features.garden + +import at.hannibal2.skyhanni.events.LorenzKeyPressEvent +import at.hannibal2.skyhanni.events.MessageSendToServerEvent +import at.hannibal2.skyhanni.features.misc.LockMouseLook +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import net.minecraft.client.Minecraft +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class GardenWarpCommands { + private val config get() = GardenAPI.config.gardenCommands + + // TODO repo + private val tpPlotPattern = "/tp (?.*)".toPattern() + + @SubscribeEvent + fun onMessageSendToServer(event: MessageSendToServerEvent) { + if (!config.warpCommands) return + if (!GardenAPI.inGarden()) return + + val message = event.message.lowercase() + + if (message == "/home") { + event.isCanceled = true + LorenzUtils.sendCommandToServer("warp garden") + LorenzUtils.chat("§aTeleported you to the spawn location!", prefix = false) + } + + if (message == "/barn") { + event.isCanceled = true + LorenzUtils.sendCommandToServer("tptoplot barn") + LockMouseLook.autoDisable() + } + + tpPlotPattern.matchMatcher(message) { + event.isCanceled = true + val plotName = group("plot") + LorenzUtils.sendCommandToServer("tptoplot $plotName") + LockMouseLook.autoDisable() + } + } + + @SubscribeEvent + fun onKeyClick(event: LorenzKeyPressEvent) { + if (!GardenAPI.inGarden()) return + if (Minecraft.getMinecraft().currentScreen != null) return + if (NEUItems.neuHasFocus()) return + + val command = when (event.keyCode) { + config.homeHotkey -> "warp garden" + config.sethomeHotkey -> "sethome" + config.barnHotkey -> "tptoplot barn" + + else -> return + } + if (command != "warp garden") { + LockMouseLook.autoDisable() + } + LorenzUtils.sendCommandToServer(command) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt index 14b430d19..4025c32e2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/LockMouseLook.kt @@ -46,4 +46,10 @@ object LockMouseLook { if (!lockedMouse) return config.lockedMouseDisplay.renderString("§eMouse Locked", posLabel = "Mouse Locked") } + + fun autoDisable() { + if (lockedMouse) { + toggleLock() + } + } } -- cgit