Skip to content

Commit

Permalink
prevent hotkey from being spammed when held (#109)
Browse files Browse the repository at this point in the history
* prevent hotkey from being spammed when held

* fix hotkey holding still working
  • Loading branch information
matthias-luger committed Oct 31, 2023
1 parent 2088cda commit ed5052c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/main/java/de/torui/coflsky/WSCommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
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;

Expand Down Expand Up @@ -97,8 +96,8 @@ private static void Flip(Command<FlipData> cmd) {
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) {
Expand All @@ -107,7 +106,6 @@ private static void handleProxyRequest(ProxyRequest[] request) {
}
}


public static void cacheMods() {
File modFolder = new File(Minecraft.getMinecraft().mcDataDir, "mods");
for (File mods : modFolder.listFiles()) {
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/de/torui/coflsky/handlers/EventRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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.*;
Expand All @@ -57,13 +58,22 @@ public void onDisconnectedFromServerEvent(ClientDisconnectionFromServerEvent eve
}
}

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();
Expand Down

0 comments on commit ed5052c

Please sign in to comment.