diff options
author | ForBai <79467608+ForBai@users.noreply.github.com> | 2022-08-18 21:21:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-18 23:21:08 +0400 |
commit | f95cdb316f0a2f984546849f83512f8dce572d85 (patch) | |
tree | 15d84dabba363fb8ea003987f503740bb84d9d2d | |
parent | 268e64acec2a9e556b575103631ddddfac698b3c (diff) | |
download | OneConfig-f95cdb316f0a2f984546849f83512f8dce572d85.tar.gz OneConfig-f95cdb316f0a2f984546849f83512f8dce572d85.tar.bz2 OneConfig-f95cdb316f0a2f984546849f83512f8dce572d85.zip |
Merge pull request #79
* Add getter in OnKeybind, so you can also get the keys
* Add documantion
* Add to api
Co-authored-by: ForBai <https://github.com/ForBai> (non-copyrightable contribution)
-rw-r--r-- | api/OneConfig.api | 1 | ||||
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/api/OneConfig.api b/api/OneConfig.api index 32318e8..c6b2936 100644 --- a/api/OneConfig.api +++ b/api/OneConfig.api @@ -203,6 +203,7 @@ public class cc/polyfrost/oneconfig/config/core/OneKeyBind { public fun addKey (I)V public fun clearKeys ()V public fun getDisplay ()Ljava/lang/String; + public fun getKeyBinds ()Ljava/util/ArrayList; public fun getSize ()I public fun isActive ()Z public fun run ()V 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<Integer> getKeyBinds() { + return keyBinds; + } } |