11package io .github .thebusybiscuit .slimefun4 .implementation .tasks ;
22
3+ import com .tcoded .folialib .wrapper .task .WrappedTask ;
34import io .github .bakedlibs .dough .collections .LoopIterator ;
45import io .github .thebusybiscuit .slimefun4 .implementation .Slimefun ;
56import io .github .thebusybiscuit .slimefun4 .implementation .guide .SurvivalSlimefunGuide ;
@@ -34,6 +35,7 @@ public class AsyncRecipeChoiceTask implements Runnable {
3435 private final ReadWriteLock lock = new ReentrantReadWriteLock ();
3536
3637 private Inventory inventory ;
38+ private WrappedTask task ;
3739
3840 /**
3941 * This will start this task for the given {@link Inventory}.
@@ -45,6 +47,7 @@ public void start(@Nonnull Inventory inv) {
4547 Validate .notNull (inv , "Inventory must not be null" );
4648
4749 inventory = inv ;
50+ task = Slimefun .getFoliaLib ().getScheduler ().runTimerAsync (this , 1 , UPDATE_INTERVAL );
4851 }
4952
5053 public void add (int slot , @ Nonnull MaterialChoice choice ) {
@@ -104,9 +107,7 @@ public void clear() {
104107 public void run () {
105108 // Terminate the task when noone is viewing the Inventory
106109 if (inventory .getViewers ().isEmpty ()) {
107- Slimefun .getFoliaLib ()
108- .getScheduler ()
109- .cancelTask (Slimefun .getFoliaLib ().getScheduler ().runTimerAsync (this , 1 , UPDATE_INTERVAL ));
110+ Slimefun .getFoliaLib ().getScheduler ().cancelTask (task );
110111 return ;
111112 }
112113
0 commit comments