mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-24 06:06:45 +01:00
update FoliaLib & add CancellableRunnable
This commit is contained in:
parent
fce6e645ea
commit
64af17db42
2
pom.xml
2
pom.xml
@ -383,7 +383,7 @@
|
||||
<dependency>
|
||||
<groupId>com.tcoded</groupId>
|
||||
<artifactId>FoliaLib</artifactId>
|
||||
<version>0.2.5</version>
|
||||
<version>0.3.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user