diff options
Diffstat (limited to 'src')
20 files changed, 140 insertions, 115 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index aeca73f3a..274fd60c7 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -283,6 +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.MinecraftConsoleFilter.Companion.initLogging import at.hannibal2.skyhanni.utils.NEUVersionCheck.checkIfNeuIsLoaded import at.hannibal2.skyhanni.utils.TabListData @@ -353,6 +354,7 @@ class SkyHanniMod { loadModule(BlockData()) loadModule(DefaultConfigFeatures) loadModule(EntityOutlineRenderer) + loadModule(KeyboardUtils) // 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 b2458bc61..1d0f0e1e4 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.LorenzUtils +import at.hannibal2.skyhanni.utils.KeyboardUtils 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<Position>, private val borde val position = positions[clickedPos] if (position.clicked) return - val dist = if (LorenzUtils.isShiftKeyDown()) 10 else 1 + val dist = if (KeyboardUtils.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/data/GuiEditManager.kt b/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt index 4313fcb35..2201ffd8b 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt @@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.core.config.Position import at.hannibal2.skyhanni.config.core.config.gui.GuiPositionEditor import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.LorenzKeyPressEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isRancherSign import at.hannibal2.skyhanni.utils.NEUItems @@ -15,32 +15,22 @@ import net.minecraft.client.gui.inventory.GuiInventory import net.minecraft.client.renderer.GlStateManager import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import org.lwjgl.input.Keyboard import java.util.UUID class GuiEditManager { - @SubscribeEvent - fun onTick(event: LorenzTickEvent) { + fun onKeyClick(event: LorenzKeyPressEvent) { if (!LorenzUtils.inSkyBlock) return + if (isInGui()) return Minecraft.getMinecraft().currentScreen?.let { if (it !is GuiInventory && it !is GuiChest && it !is GuiEditSign) return + if (it is GuiEditSign && !it.isRancherSign()) return } - if (!Keyboard.getEventKeyState()) return - val key = if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter().code + 256 else Keyboard.getEventKey() - if (SkyHanniMod.feature.gui.keyBindOpen != key) return - if (NEUItems.neuHasFocus()) return - val screen = Minecraft.getMinecraft().currentScreen - if (screen is GuiEditSign && !screen.isRancherSign()) { - return - } - - if (isInGui()) return - openGuiPositionEditor() + if (event.keyCode == SkyHanniMod.feature.gui.keyBindOpen) openGuiPositionEditor() } @SubscribeEvent(priority = EventPriority.LOWEST) diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzKeyPressEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzKeyPressEvent.kt new file mode 100644 index 000000000..70997f0c1 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/LorenzKeyPressEvent.kt @@ -0,0 +1,3 @@ +package at.hannibal2.skyhanni.events + +class LorenzKeyPressEvent(val keyCode: Int) : LorenzEvent()
\ No newline at end of file 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 b12802f3b..4d08c371f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilterGui.kt @@ -1,6 +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.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils import io.github.moulberry.moulconfig.internal.GlScissorStack @@ -58,7 +59,7 @@ class ChatFilterGui(private val history: List<ChatManager.MessageFilteringResult ) } if (mouseX in 0..w && mouseY in 0..(size * 10) && (isMouseButtonDown && !wasMouseButtonDown)) { - if (LorenzUtils.isShiftKeyDown()) { + if (KeyboardUtils.isShiftKeyDown()) { OSUtils.copyToClipboard(IChatComponent.Serializer.componentToJson(msg.message)) LorenzUtils.chat("Copied structured chat line to clipboard") } else { diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt index f96c6d260..afbf7e16b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/BurrowWarpHelper.kt @@ -3,34 +3,33 @@ package at.hannibal2.skyhanni.features.event.diana import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzKeyPressEvent import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.sorted import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.SimpleTimeMark import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent -import org.lwjgl.input.Keyboard +import kotlin.time.Duration.Companion.seconds class BurrowWarpHelper { - private var lastWarpTime = 0L + private var lastWarpTime = SimpleTimeMark.farPast() private var lastWarp: WarpPoint? = null @SubscribeEvent - fun onKeyBindPressed(event: KeyInputEvent) { + fun onKeyClick(event: LorenzKeyPressEvent) { if (!LorenzUtils.inSkyBlock) return if (LorenzUtils.skyBlockIsland != IslandType.HUB) return if (!config.burrowNearestWarp) return - if (!Keyboard.getEventKeyState()) return - val key = if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter().code + 256 else Keyboard.getEventKey() - if (config.keyBindWarp == key) { - currentWarp?.let { - if (System.currentTimeMillis() > lastWarpTime + 5_000) { - lastWarpTime = System.currentTimeMillis() - LorenzUtils.sendCommandToServer("warp " + currentWarp?.name) - lastWarp = currentWarp - } + if (event.keyCode != config.keyBindWarp) return + + currentWarp?.let { + if (lastWarpTime.passedSince() < 5.seconds) { + lastWarpTime = SimpleTimeMark.now() + LorenzUtils.sendCommandToServer("warp " + currentWarp?.name) + lastWarp = currentWarp } } } @@ -40,8 +39,7 @@ class BurrowWarpHelper { if (!LorenzUtils.inSkyBlock) return if (event.message == "§cYou haven't unlocked this fast travel destination!") { - val time = System.currentTimeMillis() - lastWarpTime - if (time < 1_000) { + if (lastWarpTime.passedSince() < 1.seconds) { lastWarp?.let { it.unlocked = false LorenzUtils.chat( @@ -53,7 +51,6 @@ class BurrowWarpHelper { } } } - } companion object { diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt index 8c139c923..caf2cb014 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/event/diana/InquisitorWaypointShare.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.EntityHealthUpdateEvent import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzKeyPressEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.PacketEvent @@ -25,8 +26,6 @@ import net.minecraft.network.play.server.S02PacketChat import net.minecraftforge.event.entity.EntityJoinWorldEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.InputEvent -import org.lwjgl.input.Keyboard import kotlin.time.Duration.Companion.seconds object InquisitorWaypointShare { @@ -164,13 +163,9 @@ object InquisitorWaypointShare { } @SubscribeEvent - fun onKeyBindPressed(event: InputEvent.KeyInputEvent) { + fun onKeyClick(event: LorenzKeyPressEvent) { if (!isEnabled()) return - if (!Keyboard.getEventKeyState()) return - val key = if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter().code + 256 else Keyboard.getEventKey() - if (config.keyBindShare == key) { - sendInquisitor() - } + if (event.keyCode == config.keyBindShare) sendInquisitor() } private fun sendDeath() { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotBorders.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotBorders.kt index 00d3461e3..05083f442 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotBorders.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotBorders.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.LorenzKeyPressEvent import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.RenderUtils.draw3DLine @@ -23,12 +23,12 @@ class GardenPlotBorders { private fun LorenzVec.addXZ(x: Int, z: Int) = add(x, 0, z) @SubscribeEvent - fun onTick(event: LorenzTickEvent) { + fun onKeyClick(event: LorenzKeyPressEvent) { if (!isEnabled()) return - - val keyPressed = if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter() else Keyboard.getEventKey() - - if (keyPressed == Keyboard.KEY_G && Keyboard.isKeyDown(Keyboard.KEY_F3)) { + if (event.keyCode == Keyboard.KEY_G && Keyboard.isKeyDown(Keyboard.KEY_F3)) { + showBorders = !showBorders + } + if (event.keyCode == Keyboard.KEY_F3 && Keyboard.isKeyDown(Keyboard.KEY_G)) { showBorders = !showBorders } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt index 5aa63b660..438fcf4a1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterOverlay.kt @@ -15,6 +15,7 @@ import at.hannibal2.skyhanni.features.garden.composter.ComposterAPI.getLevel import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.KeyboardUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector @@ -421,7 +422,7 @@ class ComposterOverlay { val name = itemName.substring(0, 2) + selected + rawItemName list.add(Renderable.link("$name §8x${itemsNeeded.addSeparators()} §7(§6$format§7)") { onClick(internalName) - if (LorenzUtils.isControlKeyDown() && lastAttemptTime.passedSince() > 500.milliseconds) { + if (KeyboardUtils.isControlKeyDown() && lastAttemptTime.passedSince() > 500.milliseconds) { lastAttemptTime = SimpleTimeMark.now() retrieveMaterials(internalName, itemName, itemsNeeded.toInt()) } 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 90274b4d6..e8add811e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt @@ -18,6 +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.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.equalsOneOf @@ -165,7 +166,7 @@ class HideNotClickableItems { } } - private fun bypasssActive() = config.notClickableItemsBypass && LorenzUtils.isControlKeyDown() + private fun bypasssActive() = config.notClickableItemsBypass && KeyboardUtils.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 d2155a416..eee1b0613 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuickCraftFeatures.kt @@ -7,6 +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.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
@@ -38,7 +39,7 @@ class QuickCraftFeatures { @SubscribeEvent
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (!isEnabled()) return
- if (LorenzUtils.isControlKeyDown()) return
+ if (KeyboardUtils.isControlKeyDown()) return
if (event.gui !is GuiChest) return
val chest = event.gui.inventorySlots as ContainerChest
@@ -61,7 +62,7 @@ class QuickCraftFeatures { val clickedItem = event.slot?.stack ?: return
- if (!LorenzUtils.isControlKeyDown() && needsQuickCraftConfirmation(clickedItem)) {
+ if (!KeyboardUtils.isControlKeyDown() && needsQuickCraftConfirmation(clickedItem)) {
event.isCanceled = true
}
}
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 98a16eb4c..9da2b804d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PasteIntoSigns.kt @@ -2,6 +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.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils import kotlinx.coroutines.launch @@ -15,7 +16,7 @@ class PasteIntoSigns { if (!LorenzUtils.onHypixel) return if (!SkyHanniMod.feature.misc.pasteIntoSigns) return - val currentlyClicked = LorenzUtils.isPastingKeysDown() + val currentlyClicked = KeyboardUtils.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 4870e2e6d..d0c81aa4a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/PetExpTooltip.kt @@ -3,6 +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.LorenzRarity import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.makeAccessible @@ -26,7 +27,7 @@ class PetExpTooltip { fun onItemTooltipLow(event: ItemTooltipEvent) { if (!LorenzUtils.inSkyBlock) return if (!config.petDisplay) return - if (!LorenzUtils.isShiftKeyDown() && !config.showAlways) return + if (!KeyboardUtils.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/compacttablist/AdvancedPlayerList.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/compacttablist/AdvancedPlayerList.kt index a490bd944..225407778 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,6 +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.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -113,7 +114,7 @@ object AdvancedPlayerList { return newList } - fun ignoreCustomTabList() = SkyHanniMod.feature.dev.debugEnabled && LorenzUtils.isControlKeyDown() + fun ignoreCustomTabList() = SkyHanniMod.feature.dev.debugEnabled && KeyboardUtils.isControlKeyDown() private val listOfSkyHanniDevsOrPeopeWhoKnowALotAboutModdingSeceneButAreBadInCoding = listOf( "hannibal2", diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt index 73382b654..fa82ba18b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/trevor/TrevorFeatures.kt @@ -6,7 +6,7 @@ import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.events.CheckRenderEntityEvent import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.LorenzKeyPressEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.withAlpha import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed @@ -21,22 +21,20 @@ import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText import at.hannibal2.skyhanni.utils.RenderUtils.drawString import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.getLorenzVec import net.minecraft.client.Minecraft -import net.minecraft.client.gui.inventory.GuiChest -import net.minecraft.client.gui.inventory.GuiEditSign -import net.minecraft.client.gui.inventory.GuiInventory import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityArmorStand import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import org.lwjgl.input.Keyboard import kotlin.concurrent.fixedRateTimer +import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds @@ -54,10 +52,10 @@ object TrevorFeatures { private var currentLabel = "§2Ready" private var trapperID: Int = 56 private var backupTrapperID: Int = 17 - private var timeLastWarped: Long = 0 + private var timeLastWarped = SimpleTimeMark.farPast() private var lastChatPrompt = "" - private var lastChatPromptTime = -1L - private var teleportBlock = -1L + private var lastChatPromptTime = SimpleTimeMark.farPast() + private var teleportBlock = SimpleTimeMark.farPast() var questActive = false var inBetweenQuests = false @@ -110,7 +108,7 @@ object TrevorFeatures { trapperReady = false TrevorTracker.startQuest(matcher) updateTrapper() - lastChatPromptTime = -1L + lastChatPromptTime = SimpleTimeMark.farPast() } matcher = talbotPatternAbove.matcher(event.message.removeColor()) @@ -126,7 +124,7 @@ object TrevorFeatures { } if (event.message.removeColor() == "[NPC] Trevor: You will have 10 minutes to find the mob from when you accept the task.") { - teleportBlock = System.currentTimeMillis() + teleportBlock = SimpleTimeMark.now() } if (event.message.contains("§r§7Click an option: §r§a§l[YES]§r§7 - §r§c§l[NO]")) { @@ -135,7 +133,7 @@ object TrevorFeatures { for (sibling in siblings) { if (sibling.chatStyle.chatClickEvent != null && sibling.chatStyle.chatClickEvent.value.contains("YES")) { - lastChatPromptTime = System.currentTimeMillis() + lastChatPromptTime = SimpleTimeMark.now() lastChatPrompt = sibling.chatStyle.chatClickEvent.value.drop(1) } } @@ -244,28 +242,27 @@ object TrevorFeatures { } @SubscribeEvent - fun onTick(event: LorenzTickEvent) { + fun onKeyClick(event: LorenzKeyPressEvent) { if (!onFarmingIsland()) return - if (!Keyboard.getEventKeyState()) return - - Minecraft.getMinecraft().currentScreen?.let { - if (it !is GuiInventory && it !is GuiChest && it !is GuiEditSign) return - } + if (Minecraft.getMinecraft().currentScreen != null) return if (NEUItems.neuHasFocus()) return - val key = if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter().code + 256 else Keyboard.getEventKey() - if (config.keyBindWarpTrapper == key) { - if (lastChatPromptTime != -1L && config.acceptQuest && !questActive && System.currentTimeMillis() - 200 > lastChatPromptTime && System.currentTimeMillis() < lastChatPromptTime + 5000) { - lastChatPromptTime = -1L + + if (event.keyCode != config.keyBindWarpTrapper) return + + if (config.acceptQuest) { + val timeSince = lastChatPromptTime.passedSince() + if (timeSince > 200.milliseconds && timeSince < 5.seconds) { + lastChatPromptTime = SimpleTimeMark.farPast() LorenzUtils.sendCommandToServer(lastChatPrompt) lastChatPrompt = "" - timeLastWarped = System.currentTimeMillis() + timeLastWarped = SimpleTimeMark.now() return } - if (System.currentTimeMillis() - timeLastWarped > 3000 && config.warpToTrapper) { - if (System.currentTimeMillis() < teleportBlock + 5000) return - LorenzUtils.sendCommandToServer("warp trapper") - timeLastWarped = System.currentTimeMillis() - } + } + + if (config.warpToTrapper && timeLastWarped.passedSince() > 3.seconds && teleportBlock.passedSince() > 5.seconds) { + LorenzUtils.sendCommandToServer("warp trapper") + timeLastWarped = SimpleTimeMark.now() } } 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 ed85ba489..5c41ff0ca 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemProfitTracker.kt @@ -16,6 +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.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList @@ -251,7 +252,7 @@ object SlayerItemProfitTracker { ) { if (System.currentTimeMillis() > lastClickDelay + 150) { - if (LorenzUtils.isControlKeyDown()) { + if (KeyboardUtils.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 59df2bf37..e74a6acff 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/ParkourWaypointSaver.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/ParkourWaypointSaver.kt @@ -1,7 +1,7 @@ package at.hannibal2.skyhanni.test import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.LorenzKeyPressEvent import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzVec @@ -10,37 +10,30 @@ import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.ParkourHelper import at.hannibal2.skyhanni.utils.RenderUtils.drawFilledBoundingBox_nea import at.hannibal2.skyhanni.utils.RenderUtils.expandBlock +import at.hannibal2.skyhanni.utils.SimpleTimeMark import net.minecraft.client.Minecraft -import net.minecraft.client.gui.inventory.GuiChest -import net.minecraft.client.gui.inventory.GuiEditSign -import net.minecraft.client.gui.inventory.GuiInventory import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import org.lwjgl.input.Keyboard +import kotlin.time.Duration.Companion.milliseconds class ParkourWaypointSaver { private val config get() = SkyHanniMod.feature.dev.waypoint - private var timeLastSaved: Long = 0 + private var timeLastSaved = SimpleTimeMark.farPast() private var locations = mutableListOf<LorenzVec>() private var parkourHelper: ParkourHelper? = null @SubscribeEvent - fun onTick(event: LorenzTickEvent) { + fun onKeyClick(event: LorenzKeyPressEvent) { if (!LorenzUtils.inSkyBlock) return - if (!Keyboard.getEventKeyState()) return + if (Minecraft.getMinecraft().currentScreen != null) return if (NEUItems.neuHasFocus()) return - if (System.currentTimeMillis() - timeLastSaved < 250) return + if (timeLastSaved.passedSince() < 250.milliseconds) return - Minecraft.getMinecraft().currentScreen?.let { - if (it !is GuiInventory && it !is GuiChest && it !is GuiEditSign) return - } - - val key = if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter().code + 256 else Keyboard.getEventKey() - if (config.deleteKey == key) { + if (config.deleteKey == event.keyCode) { locations = locations.dropLast(1).toMutableList() update() } - if (config.saveKey == key) { + if (config.saveKey == event.keyCode) { val newLocation = LorenzVec.getBlockBelowPlayer() if (locations.isNotEmpty() && newLocation == locations.last()) return locations.add(newLocation) @@ -58,7 +51,7 @@ class ParkourWaypointSaver { private fun MutableList<LorenzVec>.copyLocations() { val resultList = mutableListOf<String>() - timeLastSaved = System.currentTimeMillis() + timeLastSaved = SimpleTimeMark.now() for (location in this) { val x = location.x.toString().replace(",", ".") val y = location.y.toString().replace(",", ".") 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 cc909469e..6c2ef3a37 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/CopyErrorCommand.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.test.command import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.utils.KeyboardUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -29,7 +30,7 @@ object CopyErrorCommand { } val id = array[0] - val fullErrorMessage = LorenzUtils.isControlKeyDown() + val fullErrorMessage = KeyboardUtils.isControlKeyDown() val errorMessage = if (fullErrorMessage) { fullErrorMessages[id] } else { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/KeyboardUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/KeyboardUtils.kt new file mode 100644 index 000000000..b06a7621e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/KeyboardUtils.kt @@ -0,0 +1,53 @@ +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/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 392833f65..b5f07ba0d 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -24,8 +24,6 @@ import net.minecraft.entity.SharedMonsterAttributes import net.minecraft.event.ClickEvent import net.minecraft.event.HoverEvent import net.minecraft.util.ChatComponentText -import org.apache.commons.lang3.SystemUtils -import org.lwjgl.input.Keyboard import java.awt.Color import java.lang.reflect.Field import java.lang.reflect.Modifier @@ -290,13 +288,6 @@ object LorenzUtils { } } - fun isShiftKeyDown() = OSUtils.isKeyHeld(Keyboard.KEY_LSHIFT) || OSUtils.isKeyHeld(Keyboard.KEY_RSHIFT) - - fun isControlKeyDown() = OSUtils.isKeyHeld(Keyboard.KEY_LCONTROL) || OSUtils.isKeyHeld(Keyboard.KEY_RCONTROL) - - // 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) - // 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) { @@ -526,11 +517,6 @@ object LorenzUtils { }, duration.inWholeMilliseconds) } - fun isPastingKeysDown(): Boolean { - val modifierHeld = if (SystemUtils.IS_OS_MAC) isCommandKeyDown() else isControlKeyDown() - return modifierHeld && OSUtils.isKeyHeld(Keyboard.KEY_V) - } - val JsonPrimitive.asIntOrNull get() = takeIf { it.isNumber }?.asInt fun <T> T.transformIf(condition: T.() -> Boolean, transofmration: T.() -> T) = |