diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-06-12 17:21:36 +0700 |
---|---|---|
committer | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-06-12 17:21:36 +0700 |
commit | 636df2c2b3b8e4aa0de64cf3b9aa5c089afd70a9 (patch) | |
tree | 521d8bc2f6e6f307f62e12a3deb7a05f0f72213e /src/main/java/cc/polyfrost/oneconfig/config | |
parent | da5288bd5c80611acfeb1ebe33af1860f27f23fc (diff) | |
parent | cf8b1a7f962ad3a9c31e6698fb7caf82aac42a18 (diff) | |
download | OneConfig-636df2c2b3b8e4aa0de64cf3b9aa5c089afd70a9.tar.gz OneConfig-636df2c2b3b8e4aa0de64cf3b9aa5c089afd70a9.tar.bz2 OneConfig-636df2c2b3b8e4aa0de64cf3b9aa5c089afd70a9.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/config')
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java | 22 |
1 files changed, 19 insertions, 3 deletions
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<Integer> keyBinds = new ArrayList<>(); + protected final ArrayList<Integer> 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) { |