aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/OneConfig.api1
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java33
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;
+ }
}