mirror of
https://github.com/CompeyDev/elytra-lock-fabric.git
synced 2024-12-12 12:50:42 +00:00
28 lines
616 B
Java
28 lines
616 B
Java
package xyz.devcomp.elytralock.util;
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
import xyz.devcomp.elytralock.ElytraLock;
|
|
|
|
public class RunOnceOnToggle<T> {
|
|
private static boolean hasRun = false;
|
|
private Consumer<T> toRun;
|
|
|
|
public RunOnceOnToggle(Consumer<T> toRun) {
|
|
this.toRun = toRun;
|
|
}
|
|
|
|
public boolean run(T param) {
|
|
boolean isLocked = ElytraLock.isLocked();
|
|
if (isLocked) {
|
|
if (!hasRun) {
|
|
toRun.accept(param);
|
|
hasRun = true;
|
|
}
|
|
} else {
|
|
hasRun = false;
|
|
}
|
|
|
|
return isLocked;
|
|
}
|
|
}
|