diff --git a/src/main/java/net/minestom/server/timer/Task.java b/src/main/java/net/minestom/server/timer/Task.java index 69d7d5ad9..8b7e8218a 100644 --- a/src/main/java/net/minestom/server/timer/Task.java +++ b/src/main/java/net/minestom/server/timer/Task.java @@ -100,25 +100,25 @@ public class Task implements Runnable { * Sets up the task for correct execution. */ public void schedule() { - Int2ObjectMap tasks = this.schedulerManager.tasks; - synchronized (tasks) { - tasks.put(getId(), this); - } - if(owningExtension != null) { - this.schedulerManager.onScheduleFromExtension(owningExtension, this); - } - this.future = this.repeat == 0L ? - this.schedulerManager.getTimerExecutionService().schedule(this, this.delay, TimeUnit.MILLISECONDS) : - this.schedulerManager.getTimerExecutionService().scheduleAtFixedRate(this, this.delay, this.repeat, TimeUnit.MILLISECONDS); - } - - public void scheduleForShutdown() { - Int2ObjectMap shutdownTasks = this.schedulerManager.shutdownTasks; - synchronized (shutdownTasks) { - shutdownTasks.put(getId(), this); - } - if (owningExtension != null) { - this.schedulerManager.onScheduleShutdownFromExtension(owningExtension, this); + if(this.shutdown) { + Int2ObjectMap shutdownTasks = this.schedulerManager.shutdownTasks; + synchronized (shutdownTasks) { + shutdownTasks.put(getId(), this); + } + if (owningExtension != null) { + this.schedulerManager.onScheduleShutdownFromExtension(owningExtension, this); + } + } else { + Int2ObjectMap tasks = this.schedulerManager.tasks; + synchronized (tasks) { + tasks.put(getId(), this); + } + if (owningExtension != null) { + this.schedulerManager.onScheduleFromExtension(owningExtension, this); + } + this.future = this.repeat == 0L ? + this.schedulerManager.getTimerExecutionService().schedule(this, this.delay, TimeUnit.MILLISECONDS) : + this.schedulerManager.getTimerExecutionService().scheduleAtFixedRate(this, this.delay, this.repeat, TimeUnit.MILLISECONDS); } } diff --git a/src/main/java/net/minestom/server/timer/TaskBuilder.java b/src/main/java/net/minestom/server/timer/TaskBuilder.java index 178d70549..f1387f0c7 100644 --- a/src/main/java/net/minestom/server/timer/TaskBuilder.java +++ b/src/main/java/net/minestom/server/timer/TaskBuilder.java @@ -162,11 +162,7 @@ public class TaskBuilder { @NotNull public Task schedule() { Task task = build(); - if (this.shutdown) { - task.scheduleForShutdown(); - } else { - task.schedule(); - } + task.schedule(); return task; } }