From f95cdb316f0a2f984546849f83512f8dce572d85 Mon Sep 17 00:00:00 2001 From: ForBai <79467608+ForBai@users.noreply.github.com> Date: Thu, 18 Aug 2022 21:21:08 +0200 Subject: Merge pull request #79 * Add getter in OnKeybind, so you can also get the keys * Add documantion * Add to api Co-authored-by: ForBai (non-copyrightable contribution) --- .../oneconfig/config/core/OneKeyBind.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (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 3d3bd4b..64e95e8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java @@ -35,11 +35,18 @@ public class OneKeyBind { protected transient Runnable runnable; protected transient boolean hasRun; + /** + * @param keys The bound keys + */ public OneKeyBind(int... keys) { for (int key : keys) { keyBinds.add(key); } } + + /** + * @return If the keys are pressed + */ public boolean isActive() { if (keyBinds.size() == 0) return false; for (int keyBind : keyBinds) { @@ -51,12 +58,18 @@ public class OneKeyBind { return true; } + /** + * Run the set Runnable + */ public void run() { if (runnable == null || hasRun) return; runnable.run(); hasRun = true; } + /** + * @return The set keys as the name of the keys + */ public String getDisplay() { StringBuilder sb = new StringBuilder(); for (int keyBind : keyBinds) { @@ -66,19 +79,39 @@ public class OneKeyBind { return sb.toString().trim(); } + /** + * @param key Add a Key to keys + */ public void addKey(int key) { if (!keyBinds.contains(key)) keyBinds.add(key); } + /** + * Clear the keys List + */ public void clearKeys() { keyBinds.clear(); } + /** + * @return The amount of key in the keys List + */ public int getSize() { return keyBinds.size(); } + /** + * Set the Runnable that gets ran when OneKeyBind#run() is called + * @param runnable The Runnable to run + */ public void setRunnable(Runnable runnable) { this.runnable = runnable; } + + /** + * @return The key in the keys List + */ + public ArrayList getKeyBinds() { + return keyBinds; + } } -- cgit