From 06ef6be0fd0b7085c7121f100dff354311287e2b Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 12 Oct 2023 13:34:42 +0200 Subject: code cleanup, There are no Utils registered as listeners, and replacing OSUtils.isKeyHeld(key) to key.isKeyHeld() --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 4 +- .../config/core/config/gui/GuiPositionEditor.kt | 4 +- .../skyhanni/features/chat/ChatFilterGui.kt | 4 +- .../event/diana/InquisitorWaypointShare.kt | 4 +- .../skyhanni/features/fishing/FishingTimer.kt | 4 +- .../features/fishing/trophy/TrophyFishFillet.kt | 4 +- .../skyhanni/features/garden/ToolTooltipTweaks.kt | 4 +- .../features/garden/composter/ComposterOverlay.kt | 4 +- .../garden/farming/GardenCustomKeybinds.kt | 4 +- .../garden/visitor/GardenVisitorFeatures.kt | 4 +- .../features/inventory/HideNotClickableItems.kt | 4 +- .../features/inventory/QuickCraftFeatures.kt | 6 +- .../hannibal2/skyhanni/features/misc/ChatPeek.kt | 4 +- .../skyhanni/features/misc/HarpFeatures.kt | 4 +- .../skyhanni/features/misc/PasteIntoSigns.kt | 4 +- .../skyhanni/features/misc/PetExpTooltip.kt | 4 +- .../skyhanni/features/misc/SkyBlockKickDuration.kt | 1 + .../misc/compacttablist/AdvancedPlayerList.kt | 4 +- .../features/misc/items/EstimatedItemValue.kt | 4 +- .../CrimsonIsleReputationHelper.kt | 6 +- .../features/slayer/SlayerItemProfitTracker.kt | 4 +- .../skyhanni/test/ParkourWaypointSaver.kt | 21 +++--- .../skyhanni/test/SkyHanniDebugsAndTests.kt | 3 +- .../at/hannibal2/skyhanni/test/TestExportTools.kt | 3 +- .../hannibal2/skyhanni/test/TestShowSlotNumber.kt | 4 +- .../skyhanni/test/command/CopyErrorCommand.kt | 4 +- .../at/hannibal2/skyhanni/utils/KeyboardManager.kt | 78 ++++++++++++++++++++++ .../at/hannibal2/skyhanni/utils/KeyboardUtils.kt | 53 --------------- .../java/at/hannibal2/skyhanni/utils/OSUtils.kt | 27 -------- 29 files changed, 141 insertions(+), 137 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/utils/KeyboardUtils.kt (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 274fd60c7..528e7e4a2 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -283,7 +283,7 @@ import at.hannibal2.skyhanni.test.TestExportTools import at.hannibal2.skyhanni.test.TestShowSlotNumber import at.hannibal2.skyhanni.test.command.CopyNearbyParticlesCommand import at.hannibal2.skyhanni.utils.EntityOutlineRenderer -import at.hannibal2.skyhanni.utils.KeyboardUtils +import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.MinecraftConsoleFilter.Companion.initLogging import at.hannibal2.skyhanni.utils.NEUVersionCheck.checkIfNeuIsLoaded import at.hannibal2.skyhanni.utils.TabListData @@ -354,7 +354,7 @@ class SkyHanniMod { loadModule(BlockData()) loadModule(DefaultConfigFeatures) loadModule(EntityOutlineRenderer) - loadModule(KeyboardUtils) + loadModule(KeyboardManager) // APIs loadModule(BazaarApi()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt index 1d0f0e1e4..4e72a0fb4 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/core/config/gui/GuiPositionEditor.kt @@ -24,7 +24,7 @@ import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsY import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getDummySize import at.hannibal2.skyhanni.data.OtherInventoryData import at.hannibal2.skyhanni.utils.GuiRenderUtils -import at.hannibal2.skyhanni.utils.KeyboardUtils +import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzUtils.round import net.minecraft.client.Minecraft import net.minecraft.client.gui.GuiScreen @@ -177,7 +177,7 @@ class GuiPositionEditor(private val positions: List, private val borde val position = positions[clickedPos] if (position.clicked) return - val dist = if (KeyboardUtils.isShiftKeyDown()) 10 else 1 + val dist = if (KeyboardManager.isShiftKeyDown()) 10 else 1 val elementWidth = position.getDummySize(true).x val elementHeight = position.getDummySize(true).y when (keyCode) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt index 4d08c371f..05a3ba456 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.features.chat import at.hannibal2.skyhanni.data.ChatManager -import at.hannibal2.skyhanni.utils.KeyboardUtils +import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils import io.github.moulberry.moulconfig.internal.GlScissorStack @@ -59,7 +59,7 @@ class ChatFilterGui(private val history: List 500.milliseconds) { + if (KeyboardManager.isControlKeyDown() && lastAttemptTime.passedSince() > 500.milliseconds) { lastAttemptTime = SimpleTimeMark.now() retrieveMaterials(internalName, itemName, itemsNeeded.toInt()) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt index 06861c269..16393cbab 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenCustomKeybinds.kt @@ -3,7 +3,7 @@ package at.hannibal2.skyhanni.features.garden.farming import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.mixins.transformers.AccessorKeyBinding -import at.hannibal2.skyhanni.utils.OSUtils +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiEditSign import net.minecraft.client.settings.KeyBinding @@ -53,7 +53,7 @@ object GardenCustomKeybinds { if (!isActive()) return val override = map[keyBinding] ?: return val keyCode = override() - cir.returnValue = OSUtils.isKeyHeld(keyCode) + cir.returnValue = keyCode.isKeyHeld() } @JvmStatic diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index e34b0ab84..ab13c2aec 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -31,6 +31,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getItemName import at.hannibal2.skyhanni.utils.ItemUtils.getItemNameOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzLogger @@ -43,7 +44,6 @@ import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.RenderUtils.drawString import at.hannibal2.skyhanni.utils.RenderUtils.exactLocation import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems @@ -305,7 +305,7 @@ class GardenVisitorFeatures { visitor.hasReward()?.let { if (config.visitorRewardWarning.preventRefusing) { - if (OSUtils.isKeyHeld(config.visitorRewardWarning.bypassKey)) { + if (config.visitorRewardWarning.bypassKey.isKeyHeld()) { LorenzUtils.chat("§e[SkyHanni] §cBypassed blocking refusal of visitor ${visitor.visitorName} §7(${it.displayName}§7)") return } diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt index e8add811e..79b1ddb7b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt @@ -18,7 +18,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_old import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.isEnchanted import at.hannibal2.skyhanni.utils.ItemUtils.isVanilla -import at.hannibal2.skyhanni.utils.KeyboardUtils +import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.equalsOneOf @@ -166,7 +166,7 @@ class HideNotClickableItems { } } - private fun bypasssActive() = config.notClickableItemsBypass && KeyboardUtils.isControlKeyDown() + private fun bypasssActive() = config.notClickableItemsBypass && KeyboardManager.isControlKeyDown() private fun isDisabled(): Boolean { if (bypassUntil > System.currentTimeMillis()) return true diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt index eee1b0613..0fd9f2cc2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt @@ -7,7 +7,7 @@ import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.KeyboardUtils +import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -39,7 +39,7 @@ class QuickCraftFeatures { @SubscribeEvent fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { if (!isEnabled()) return - if (KeyboardUtils.isControlKeyDown()) return + if (KeyboardManager.isControlKeyDown()) return if (event.gui !is GuiChest) return val chest = event.gui.inventorySlots as ContainerChest @@ -62,7 +62,7 @@ class QuickCraftFeatures { val clickedItem = event.slot?.stack ?: return - if (!KeyboardUtils.isControlKeyDown() && needsQuickCraftConfirmation(clickedItem)) { + if (!KeyboardManager.isControlKeyDown() && needsQuickCraftConfirmation(clickedItem)) { event.isCanceled = true } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ChatPeek.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ChatPeek.kt index efc6e3d1e..eb9b49a78 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/ChatPeek.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ChatPeek.kt @@ -1,8 +1,8 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.NEUItems -import at.hannibal2.skyhanni.utils.OSUtils import io.github.moulberry.moulconfig.gui.GuiScreenElementWrapper import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiEditSign @@ -21,6 +21,6 @@ object ChatPeek { if (NEUItems.neuHasFocus()) return false - return OSUtils.isKeyHeld(key) + return key.isKeyHeld() } } \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/HarpFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/HarpFeatures.kt index 72cad7e00..e483aa980 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/HarpFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/HarpFeatures.kt @@ -4,8 +4,8 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.events.RenderItemTipEvent import at.hannibal2.skyhanni.utils.InventoryUtils.openInventoryName +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.SimpleTimeMark import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiChest @@ -40,7 +40,7 @@ class HarpFeatures { val chest = event.gui as? GuiChest ?: return for (key in keys) { - if (OSUtils.isKeyHeld(key)) { + if (key.isKeyHeld()) { if (lastClick.passedSince() > 200.milliseconds) { Minecraft.getMinecraft().playerController.windowClick( chest.inventorySlots.windowId, diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt index 9da2b804d..5bedd57cc 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt @@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzTickEvent -import at.hannibal2.skyhanni.utils.KeyboardUtils +import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils import kotlinx.coroutines.launch @@ -16,7 +16,7 @@ class PasteIntoSigns { if (!LorenzUtils.onHypixel) return if (!SkyHanniMod.feature.misc.pasteIntoSigns) return - val currentlyClicked = KeyboardUtils.isPastingKeysDown() + val currentlyClicked = KeyboardManager.isPastingKeysDown() if (!lastClicked && currentlyClicked) { SkyHanniMod.coroutineScope.launch { OSUtils.readFromClipboard()?.let { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt index d0c81aa4a..e39973d15 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt @@ -3,7 +3,7 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrNull import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.KeyboardUtils +import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzRarity import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.makeAccessible @@ -27,7 +27,7 @@ class PetExpTooltip { fun onItemTooltipLow(event: ItemTooltipEvent) { if (!LorenzUtils.inSkyBlock) return if (!config.petDisplay) return - if (!KeyboardUtils.isShiftKeyDown() && !config.showAlways) return + if (!KeyboardManager.isShiftKeyDown() && !config.showAlways) return val itemStack = event.itemStack ?: return val petExperience = itemStack.getPetExp()?.round(1) ?: return diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/SkyBlockKickDuration.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/SkyBlockKickDuration.kt index 3759d432e..e5763ed58 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/SkyBlockKickDuration.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/SkyBlockKickDuration.kt @@ -24,6 +24,7 @@ class SkyBlockKickDuration { fun onChat(event: LorenzChatEvent) { if (!isEnabled()) return if (event.message == "§cYou were kicked while joining that server!") { + //if is in hub: enable rn kickMessage = true } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt index 225407778..59ecd2724 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt @@ -6,7 +6,7 @@ import at.hannibal2.skyhanni.data.FriendAPI import at.hannibal2.skyhanni.data.GuildAPI import at.hannibal2.skyhanni.data.PartyAPI import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager -import at.hannibal2.skyhanni.utils.KeyboardUtils +import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -114,7 +114,7 @@ object AdvancedPlayerList { return newList } - fun ignoreCustomTabList() = SkyHanniMod.feature.dev.debugEnabled && KeyboardUtils.isControlKeyDown() + fun ignoreCustomTabList() = SkyHanniMod.feature.dev.debugEnabled && KeyboardManager.isControlKeyDown() private val listOfSkyHanniDevsOrPeopeWhoKnowALotAboutModdingSeceneButAreBadInCoding = listOf( "hannibal2", diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt index 60a790297..0386300e6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt @@ -16,6 +16,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LorenzRarity import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList @@ -29,7 +30,6 @@ import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull import at.hannibal2.skyhanni.utils.NEUItems.manager import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.GemstoneSlotType import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getAbilityScrolls @@ -97,7 +97,7 @@ object EstimatedItemValue { fun onRenderOverlay(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { if (!LorenzUtils.inSkyBlock) return if (!config.estimatedIemValueEnabled) return - if (!OSUtils.isKeyHeld(config.estimatedItemValueHotkey) && !config.estimatedIemValueAlwaysEnabled) return + if (!config.estimatedItemValueHotkey.isKeyHeld() && !config.estimatedIemValueAlwaysEnabled) return if (System.currentTimeMillis() > lastToolTipTime + 200) return config.itemPriceDataPos.renderStringsAndItems(display, posLabel = "Estimated Item Value") diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/CrimsonIsleReputationHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/CrimsonIsleReputationHelper.kt index 7fa82bcf9..5906d136a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/CrimsonIsleReputationHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/CrimsonIsleReputationHelper.kt @@ -11,10 +11,10 @@ import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.features.nether.reputationhelper.dailykuudra.DailyKuudraBossHelper import at.hannibal2.skyhanni.features.nether.reputationhelper.dailyquest.DailyQuestHelper import at.hannibal2.skyhanni.features.nether.reputationhelper.miniboss.DailyMiniBossHelper +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzVec -import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.TabListData import com.google.gson.JsonObject @@ -112,7 +112,7 @@ class CrimsonIsleReputationHelper(skyHanniMod: SkyHanniMod) { if (!LorenzUtils.inSkyBlock) return if (LorenzUtils.skyBlockIsland != IslandType.CRIMSON_ISLE) return - if (config.useHotkey && !OSUtils.isKeyHeld(config.hotkey)) { + if (config.useHotkey && !config.hotkey.isKeyHeld()) { return } @@ -162,7 +162,7 @@ class CrimsonIsleReputationHelper(skyHanniMod: SkyHanniMod) { fun showLocations() = when (config.showLocation) { 0 -> true - 1 -> OSUtils.isKeyHeld(config.hotkey) + 1 -> config.hotkey.isKeyHeld() else -> false } } \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt index 5c41ff0ca..00d4ad0d2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt @@ -16,7 +16,7 @@ import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData import at.hannibal2.skyhanni.test.PriceSource import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.KeyboardUtils +import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList @@ -252,7 +252,7 @@ object SlayerItemProfitTracker { ) { if (System.currentTimeMillis() > lastClickDelay + 150) { - if (KeyboardUtils.isControlKeyDown()) { + if (KeyboardManager.isControlKeyDown()) { itemLog.items.remove(internalName) LorenzUtils.chat("§e[SkyHanni] Removed $cleanName §efrom slayer profit display.") lastClickDelay = System.currentTimeMillis() + 500 diff --git a/src/main/java/at/hannibal2/skyhanni/test/ParkourWaypointSaver.kt b/src/main/java/at/hannibal2/skyhanni/test/ParkourWaypointSaver.kt index e74a6acff..65e2e6275 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/ParkourWaypointSaver.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/ParkourWaypointSaver.kt @@ -29,15 +29,18 @@ class ParkourWaypointSaver { if (NEUItems.neuHasFocus()) return if (timeLastSaved.passedSince() < 250.milliseconds) return - if (config.deleteKey == event.keyCode) { - locations = locations.dropLast(1).toMutableList() - update() - } - if (config.saveKey == event.keyCode) { - val newLocation = LorenzVec.getBlockBelowPlayer() - if (locations.isNotEmpty() && newLocation == locations.last()) return - locations.add(newLocation) - update() + when (event.keyCode) { + config.deleteKey -> { + locations = locations.dropLast(1).toMutableList() + update() + } + + config.saveKey -> { + val newLocation = LorenzVec.getBlockBelowPlayer() + if (locations.isNotEmpty() && newLocation == locations.last()) return + locations.add(newLocation) + update() + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt index 3a0660c2d..6e2d2d1ab 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt @@ -14,6 +14,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrNull import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LorenzDebug import at.hannibal2.skyhanni.utils.LorenzLogger @@ -267,7 +268,7 @@ class SkyHanniDebugsAndTests { @SubscribeEvent fun onKeybind(event: GuiScreenEvent.KeyboardInputEvent.Post) { - if (!OSUtils.isKeyHeld(SkyHanniMod.feature.dev.copyInternalName)) return + if (!SkyHanniMod.feature.dev.copyInternalName.isKeyHeld()) return val gui = event.gui as? GuiContainer ?: return val focussedSlot = gui.slotUnderMouse ?: return val stack = focussedSlot.stack ?: return diff --git a/src/main/java/at/hannibal2/skyhanni/test/TestExportTools.kt b/src/main/java/at/hannibal2/skyhanni/test/TestExportTools.kt index 77547770a..426562e6f 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/TestExportTools.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/TestExportTools.kt @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.test import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.utils.ItemStackTypeAdapterFactory import at.hannibal2.skyhanni.utils.KSerializable +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.KotlinTypeAdapterFactory import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NBTTypeAdapter @@ -47,7 +48,7 @@ object TestExportTools { @SubscribeEvent fun onKeybind(event: GuiScreenEvent.KeyboardInputEvent.Post) { - if (!OSUtils.isKeyHeld(SkyHanniMod.feature.dev.copyNBTDataCompressed)) return + if (!SkyHanniMod.feature.dev.copyNBTDataCompressed.isKeyHeld()) return val gui = event.gui as? GuiContainer ?: return val focussedSlot = gui.slotUnderMouse ?: return val stack = focussedSlot.stack ?: return diff --git a/src/main/java/at/hannibal2/skyhanni/test/TestShowSlotNumber.kt b/src/main/java/at/hannibal2/skyhanni/test/TestShowSlotNumber.kt index 115cef414..9b11abd60 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/TestShowSlotNumber.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/TestShowSlotNumber.kt @@ -2,14 +2,14 @@ package at.hannibal2.skyhanni.test import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.RenderInventoryItemTipEvent -import at.hannibal2.skyhanni.utils.OSUtils +import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class TestShowSlotNumber { @SubscribeEvent fun onRenderItemTip(event: RenderInventoryItemTipEvent) { - if (OSUtils.isKeyHeld(SkyHanniMod.feature.dev.showSlotNumberKey)) { + if (SkyHanniMod.feature.dev.showSlotNumberKey.isKeyHeld()) { val slotIndex = event.slot.slotIndex event.stackTip = "$slotIndex" } diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt index 6c2ef3a37..8c713558f 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.test.command import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.utils.KeyboardUtils +import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -30,7 +30,7 @@ object CopyErrorCommand { } val id = array[0] - val fullErrorMessage = KeyboardUtils.isControlKeyDown() + val fullErrorMessage = KeyboardManager.isControlKeyDown() val errorMessage = if (fullErrorMessage) { fullErrorMessages[id] } else { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt b/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt new file mode 100644 index 000000000..21a17e740 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/KeyboardManager.kt @@ -0,0 +1,78 @@ +package at.hannibal2.skyhanni.utils + +import at.hannibal2.skyhanni.events.LorenzKeyPressEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import io.github.moulberry.moulconfig.internal.KeybindHelper +import net.minecraft.client.settings.KeyBinding +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.apache.commons.lang3.SystemUtils +import org.lwjgl.input.Keyboard +import org.lwjgl.input.Mouse + +object KeyboardManager { + private var lastClickedMouseButton = -1 + + // A mac-only key, represents Windows key on windows (but different key code) + fun isCommandKeyDown() = Keyboard.KEY_LMETA.isKeyHeld() || Keyboard.KEY_RMETA.isKeyHeld() + fun isControlKeyDown() = Keyboard.KEY_LCONTROL.isKeyHeld() || Keyboard.KEY_RCONTROL.isKeyHeld() + fun isShiftKeyDown() = Keyboard.KEY_LSHIFT.isKeyHeld() || Keyboard.KEY_RSHIFT.isKeyHeld() + + fun isPastingKeysDown(): Boolean { + val modifierHeld = if (SystemUtils.IS_OS_MAC) isCommandKeyDown() else isControlKeyDown() + return modifierHeld && Keyboard.KEY_V.isKeyHeld() + } + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (Mouse.getEventButtonState() && Mouse.getEventButton() != -1) { + val key = Mouse.getEventButton() - 100 + LorenzKeyPressEvent(key).postAndCatch() + lastClickedMouseButton = key + return + } + + if (Keyboard.getEventKeyState() && Keyboard.getEventKey() != 0) { + val key = Keyboard.getEventKey() + LorenzKeyPressEvent(key).postAndCatch() + lastClickedMouseButton = -1 + return + } + + if (Mouse.getEventButton() == -1 && lastClickedMouseButton != -1) { + if (lastClickedMouseButton.isKeyHeld()) { + LorenzKeyPressEvent(lastClickedMouseButton).postAndCatch() + println("still holding") + return + } + lastClickedMouseButton = -1 + } + + // I don't know when this is needed + if (Keyboard.getEventKey() == 0) { + LorenzKeyPressEvent(Keyboard.getEventCharacter().code + 256).postAndCatch() + } + } + + fun KeyBinding.isActive(): Boolean { + if (!Keyboard.isCreated()) return false + try { + if (keyCode.isKeyHeld()) return true + } catch (e: IndexOutOfBoundsException) { + println("KeyBinding isActive caused an IndexOutOfBoundsException with keyCode: $keyCode") + e.printStackTrace() + return false + } + return this.isKeyDown || this.isPressed + } + + fun Int.isKeyHeld(): Boolean { + if (this == 0) return false + return if (this < 0) { + Mouse.isButtonDown(this + 100) + } else { + KeybindHelper.isKeyDown(this) + } + } + + fun getKeyName(keyCode: Int): String = KeybindHelper.getKeyName(keyCode) +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/KeyboardUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/KeyboardUtils.kt deleted file mode 100644 index b06a7621e..000000000 --- a/src/main/java/at/hannibal2/skyhanni/utils/KeyboardUtils.kt +++ /dev/null @@ -1,53 +0,0 @@ -package at.hannibal2.skyhanni.utils - -import at.hannibal2.skyhanni.events.LorenzKeyPressEvent -import at.hannibal2.skyhanni.events.LorenzTickEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import org.apache.commons.lang3.SystemUtils -import org.lwjgl.input.Keyboard -import org.lwjgl.input.Mouse - -object KeyboardUtils { - private var lastClickedMouseButton = -1 - - // A mac-only key, represents Windows key on windows (but different key code) - fun isCommandKeyDown() = OSUtils.isKeyHeld(Keyboard.KEY_LMETA) || OSUtils.isKeyHeld(Keyboard.KEY_RMETA) - fun isControlKeyDown() = OSUtils.isKeyHeld(Keyboard.KEY_LCONTROL) || OSUtils.isKeyHeld(Keyboard.KEY_RCONTROL) - fun isShiftKeyDown() = OSUtils.isKeyHeld(Keyboard.KEY_LSHIFT) || OSUtils.isKeyHeld(Keyboard.KEY_RSHIFT) - - fun isPastingKeysDown(): Boolean { - val modifierHeld = if (SystemUtils.IS_OS_MAC) isCommandKeyDown() else isControlKeyDown() - return modifierHeld && OSUtils.isKeyHeld(Keyboard.KEY_V) - } - - @SubscribeEvent - fun onTick(event: LorenzTickEvent) { - if (Mouse.getEventButtonState() && Mouse.getEventButton() != -1) { - val key = Mouse.getEventButton() - 100 - LorenzKeyPressEvent(key).postAndCatch() - lastClickedMouseButton = key - return - } - - if (Keyboard.getEventKeyState() && Keyboard.getEventKey() != 0) { - val key = Keyboard.getEventKey() - LorenzKeyPressEvent(key).postAndCatch() - lastClickedMouseButton = -1 - return - } - - if (Mouse.getEventButton() == -1 && lastClickedMouseButton != -1) { - if (OSUtils.isKeyHeld(lastClickedMouseButton)) { - LorenzKeyPressEvent(lastClickedMouseButton).postAndCatch() - println("still holding") - return - } - lastClickedMouseButton = -1 - } - - // I don't know when this is needed - if (Keyboard.getEventKey() == 0) { - LorenzKeyPressEvent(Keyboard.getEventCharacter().code + 256).postAndCatch() - } - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt index 981ea87c3..b083b2d3b 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt @@ -1,9 +1,5 @@ package at.hannibal2.skyhanni.utils -import io.github.moulberry.moulconfig.internal.KeybindHelper -import net.minecraft.client.settings.KeyBinding -import org.lwjgl.input.Keyboard -import org.lwjgl.input.Mouse import java.awt.Desktop import java.io.IOException import java.net.URI @@ -30,27 +26,4 @@ object OSUtils { } suspend fun readFromClipboard() = ClipboardUtils.readFromClipboard() - - fun KeyBinding.isActive(): Boolean { - if (!Keyboard.isCreated()) return false - try { - if (isKeyHeld(keyCode)) return true - } catch (e: IndexOutOfBoundsException) { - println("KeyBinding isActive caused an IndexOutOfBoundsException with keyCode: $keyCode") - e.printStackTrace() - return false - } - return this.isKeyDown || this.isPressed - } - - fun isKeyHeld(keyCode: Int): Boolean { - if (keyCode == 0) return false - return if (keyCode < 0) { - Mouse.isButtonDown(keyCode + 100) - } else { - KeybindHelper.isKeyDown(keyCode) - } - } - - fun getKeyName(keyCode: Int): String = KeybindHelper.getKeyName(keyCode) } -- cgit