update FoliaLib & add CancellableRunnable

This commit is contained in:
HSGamer
2023-08-20 21:22:21 +07:00
parent fce6e645ea
commit 64af17db42
2 changed files with 29 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
package com.gmail.nossr50.util;
import com.tcoded.folialib.wrapper.task.WrappedTask;
import java.util.function.Consumer;
public abstract class CancellableRunnable implements Consumer<WrappedTask> {
private boolean cancelled = false;
public void cancel() {
cancelled = true;
}
public abstract void run();
@Override
public void accept(WrappedTask wrappedTask) {
// Run the task if it hasn't been cancelled
if (!cancelled) {
run();
}
// Cancel the task if it has been cancelled after running
if (cancelled) {
wrappedTask.cancel();
}
}
}