Skip to content

Timer : Cancellation

Xenxia edited this page Feb 27, 2021 · 1 revision
import fr.cheeseGrinder.bukkitTimer.Timer;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

public class TestTimer {
    private final Timer timer;

    public TestTimer(JavaPlugin plugin) {
        this.timer = new Timer(plugin);
    }

    public void runCancellation() {
        // Loop 1 seconds callback was called
        BukkitTask loop = timer.runLoopAsync(20, () -> {
            Bukkit.broadcastMessage("called after 1 seconds");
        });
        
        loop.cancel();
    }
}
Clone this wiki locally