minecraft-source/src/com/mojang/realmsclient/KeyCombo.java

41 lines
1.0 KiB
Java
Raw Normal View History

2020-07-22 06:23:34 +01:00
package com.mojang.realmsclient;
import java.util.Arrays;
public class KeyCombo {
private final char[] chars;
private int matchIndex;
private final Runnable onCompletion;
public KeyCombo(final char[] arr, final Runnable runnable) {
this.onCompletion = runnable;
if (arr.length < 1) {
throw new IllegalArgumentException("Must have at least one char");
}
this.chars = arr;
}
public boolean keyPressed(final char character) {
2020-07-22 06:32:50 +01:00
if (character == this.chars[this.matchIndex++]) {
if (this.matchIndex == this.chars.length) {
this.reset();
this.onCompletion.run();
return true;
}
2020-07-22 06:23:34 +01:00
}
2020-07-22 06:32:50 +01:00
else {
2020-07-22 06:23:34 +01:00
this.reset();
}
return false;
}
public void reset() {
this.matchIndex = 0;
}
@Override
public String toString() {
return "KeyCombo{chars=" + Arrays.toString(this.chars) + ", matchIndex=" + this.matchIndex + '}';
}
}