mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 22:47:49 +01:00
Move functionality from TaskBuilder#schedule
to Task#schedule
and Task#scheduleForShutdown
This commit is contained in:
parent
3ce51ff470
commit
2674ca933e
@ -100,6 +100,10 @@ public class Task implements Runnable {
|
|||||||
* Sets up the task for correct execution.
|
* Sets up the task for correct execution.
|
||||||
*/
|
*/
|
||||||
public void schedule() {
|
public void schedule() {
|
||||||
|
Int2ObjectMap<Task> tasks = this.schedulerManager.tasks;
|
||||||
|
synchronized (tasks) {
|
||||||
|
tasks.put(getId(), this);
|
||||||
|
}
|
||||||
if(owningExtension != null) {
|
if(owningExtension != null) {
|
||||||
this.schedulerManager.onScheduleFromExtension(owningExtension, this);
|
this.schedulerManager.onScheduleFromExtension(owningExtension, this);
|
||||||
}
|
}
|
||||||
@ -108,6 +112,16 @@ public class Task implements Runnable {
|
|||||||
this.schedulerManager.getTimerExecutionService().scheduleAtFixedRate(this, this.delay, this.repeat, TimeUnit.MILLISECONDS);
|
this.schedulerManager.getTimerExecutionService().scheduleAtFixedRate(this, this.delay, this.repeat, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void scheduleForShutdown() {
|
||||||
|
Int2ObjectMap<Task> shutdownTasks = this.schedulerManager.shutdownTasks;
|
||||||
|
synchronized (shutdownTasks) {
|
||||||
|
shutdownTasks.put(getId(), this);
|
||||||
|
}
|
||||||
|
if (owningExtension != null) {
|
||||||
|
this.schedulerManager.onScheduleShutdownFromExtension(owningExtension, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current status of the task.
|
* Gets the current status of the task.
|
||||||
*
|
*
|
||||||
|
@ -144,27 +144,10 @@ public class TaskBuilder {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public Task schedule() {
|
public Task schedule() {
|
||||||
Task task = new Task(
|
Task task = build();
|
||||||
this.schedulerManager,
|
|
||||||
this.runnable,
|
|
||||||
this.shutdown,
|
|
||||||
this.delay,
|
|
||||||
this.repeat,
|
|
||||||
this.isTransient,
|
|
||||||
this.owningExtension);
|
|
||||||
if (this.shutdown) {
|
if (this.shutdown) {
|
||||||
Int2ObjectMap<Task> shutdownTasks = this.schedulerManager.shutdownTasks;
|
task.scheduleForShutdown();
|
||||||
synchronized (shutdownTasks) {
|
|
||||||
shutdownTasks.put(task.getId(), task);
|
|
||||||
}
|
|
||||||
if (owningExtension != null) {
|
|
||||||
this.schedulerManager.onScheduleShutdownFromExtension(owningExtension, task);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Int2ObjectMap<Task> tasks = this.schedulerManager.tasks;
|
|
||||||
synchronized (tasks) {
|
|
||||||
tasks.put(task.getId(), task);
|
|
||||||
}
|
|
||||||
task.schedule();
|
task.schedule();
|
||||||
}
|
}
|
||||||
return task;
|
return task;
|
||||||
|
Loading…
Reference in New Issue
Block a user