How can I cancel Task?

I have created a Task like this.

Task task = Task.builder().execute(() → {

}).delay(0, TimeUnit.SECONDS).interval(1, TimeUnit.SECONDS).plugin(Main.getInstance().getContainer())

in sponge 7.0
I can use → task.cancel();

but In sponge 8.0, I didn’t found the method like cancel();

How can I cancel the task?

Please help me.

Hi. When you submit a task for scheduling, you gain a ScheduledTask, that has a method for cancelling it on it

1 Like

How can I get ScheduledTask from Task ?

Could you please send me an example code for create a ScheduledTask ?

Thank you so much!


Task task;
ScheduledTask scheduled = Sponge.asyncScheduler().submit(task);

Or if your scheduled task is synced

Task task;
ScheduledTask scheduled = Sponge.server().scheduler().submit(task);
1 Like

Thank for you care!