aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/config
diff options
context:
space:
mode:
authorForBai <79467608+ForBai@users.noreply.github.com>2022-08-18 21:21:08 +0200
committerGitHub <noreply@github.com>2022-08-18 23:21:08 +0400
commitf95cdb316f0a2f984546849f83512f8dce572d85 (patch)
tree15d84dabba363fb8ea003987f503740bb84d9d2d /src/main/java/cc/polyfrost/oneconfig/config
parent268e64acec2a9e556b575103631ddddfac698b3c (diff)
downloadOneConfig-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)
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/config')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java33
1 files changed, 33 insertions, 0 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 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;
+ }
}