diff options
author | matthias-luger <58751503+matthias-luger@users.noreply.github.com> | 2023-10-31 16:12:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-31 16:12:14 +0100 |
commit | ed5052c23c2e48cd696e3708bbbfc911dcc1718e (patch) | |
tree | d2a8ad8dca0e11680804d92e85ef41a841336312 /src/main/java | |
parent | 2088cda8b5a9d17047ddc1efd8a5c328795aa58d (diff) | |
download | COFL-ed5052c23c2e48cd696e3708bbbfc911dcc1718e.tar.gz COFL-ed5052c23c2e48cd696e3708bbbfc911dcc1718e.tar.bz2 COFL-ed5052c23c2e48cd696e3708bbbfc911dcc1718e.zip |
prevent hotkey from being spammed when held (#109)
* prevent hotkey from being spammed when held
* fix hotkey holding still working
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/torui/coflsky/WSCommandHandler.java | 6 | ||||
-rw-r--r-- | src/main/java/de/torui/coflsky/handlers/EventRegistry.java | 12 |
2 files changed, 13 insertions, 5 deletions
diff --git a/src/main/java/de/torui/coflsky/WSCommandHandler.java b/src/main/java/de/torui/coflsky/WSCommandHandler.java index 8d22b62..5bae5b2 100644 --- a/src/main/java/de/torui/coflsky/WSCommandHandler.java +++ b/src/main/java/de/torui/coflsky/WSCommandHandler.java @@ -25,7 +25,6 @@ import net.minecraft.util.ChatStyle; import net.minecraft.util.IChatComponent; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.ClientCommandHandler; -import net.minecraftforge.common.ForgeModContainer; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.ModContainer; @@ -97,8 +96,8 @@ public class WSCommandHandler { Command<ChatMessageData[]> showCmd = new Command<ChatMessageData[]>(CommandType.ChatMessage, messages); ChatMessage(showCmd); flipHandler.fds.Insert(cmd.getData()); - // trigger the keyevent to execute the event handler - CoflSky.Events.onKeyEvent(null); + // trigger the onAfterHotkeyPressed function to open the flip if the correct hotkey is currently still pressed + EventRegistry.onAfterKeyPressed(); } private static void handleProxyRequest(ProxyRequest[] request) { @@ -107,7 +106,6 @@ public class WSCommandHandler { } } - public static void cacheMods() { File modFolder = new File(Minecraft.getMinecraft().mcDataDir, "mods"); for (File mods : modFolder.listFiles()) { diff --git a/src/main/java/de/torui/coflsky/handlers/EventRegistry.java b/src/main/java/de/torui/coflsky/handlers/EventRegistry.java index 81300ad..3ebd168 100644 --- a/src/main/java/de/torui/coflsky/handlers/EventRegistry.java +++ b/src/main/java/de/torui/coflsky/handlers/EventRegistry.java @@ -38,6 +38,7 @@ import net.minecraftforge.fml.common.network.FMLNetworkEvent.ClientDisconnection import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.lwjgl.input.Keyboard; import static de.torui.coflsky.CoflSky.config; import static de.torui.coflsky.handlers.DescriptionHandler.*; @@ -57,13 +58,22 @@ public class EventRegistry { } } - public long LastClick = System.currentTimeMillis(); + public static long LastClick = System.currentTimeMillis(); + public static Boolean LastHotkeyState; private DescriptionHandler descriptionHandler; @SideOnly(Side.CLIENT) @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true) public void onKeyEvent(KeyInputEvent event) { + if (LastHotkeyState != null && Keyboard.getEventKeyState() == LastHotkeyState) { + return; + } + LastHotkeyState = Keyboard.getEventKeyState(); + onAfterKeyPressed(); + } + + public static void onAfterKeyPressed() { if (CoflSky.keyBindings[0].isPressed()) { if (WSCommandHandler.lastOnClickEvent != null) { FlipData f = WSCommandHandler.flipHandler.fds.GetLastFlip(); |