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

@ -383,7 +383,7 @@
<dependency> <dependency>
<groupId>com.tcoded</groupId> <groupId>com.tcoded</groupId>
<artifactId>FoliaLib</artifactId> <artifactId>FoliaLib</artifactId>
<version>0.2.5</version> <version>0.3.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

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();
}
}
}