Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent hotkey from being spammed when held #109

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading