From 0f853804ef7c626e9c31749d6f948aa6bb23f4db Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Sun, 12 Jun 2022 12:17:43 +0200 Subject: prefernces, keybinds, scrolling fixes --- .../oneconfig/config/core/OneKeyBind.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/main/java/cc/polyfrost/oneconfig/config') diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java index d62247c..229e4d1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java @@ -5,22 +5,38 @@ import cc.polyfrost.oneconfig.libs.universal.UKeyboard; import java.util.ArrayList; public class OneKeyBind { - private final ArrayList keyBinds = new ArrayList<>(); + protected final ArrayList keyBinds = new ArrayList<>(); + protected final Runnable runnable; + protected boolean hasRun; - public OneKeyBind(int... keys) { + public OneKeyBind(Runnable runnable, int... keys) { + this.runnable = runnable; for (int key : keys) { keyBinds.add(key); } } + public OneKeyBind(int... keys) { + this(null, keys); + } + public boolean isActive() { if (keyBinds.size() == 0) return false; for (int keyBind : keyBinds) { - if (!UKeyboard.isKeyDown(keyBind)) return false; + if (!UKeyboard.isKeyDown(keyBind)) { + hasRun = false; + return false; + } } return true; } + public void run() { + if (runnable == null || hasRun) return; + runnable.run(); + hasRun = true; + } + public String getDisplay() { StringBuilder sb = new StringBuilder(); for (int keyBind : keyBinds) { -- cgit