Added onCreateTasks

This commit is contained in:
Will FP
2024-02-08 14:22:47 +00:00
parent c977cb2602
commit 47c8617d3d

View File

@@ -167,7 +167,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike, Regist
/** /**
* The tasks to run on task creation. * The tasks to run on task creation.
*/ */
private final ListMap<LifecyclePosition, Runnable> createTasks = new ListMap<>(); private final ListMap<LifecyclePosition, Runnable> onCreateTasks = new ListMap<>();
/** /**
* Create a new plugin. * Create a new plugin.
@@ -638,7 +638,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike, Regist
this.handleLifecycle(this.onReload, this::handleReload); this.handleLifecycle(this.onReload, this::handleReload);
if (cancelTasks) { if (cancelTasks) {
this.handleLifecycle(this.createTasks, this::createTasks); this.handleLifecycle(this.onCreateTasks, this::createTasks);
} }
for (Extension extension : this.extensionLoader.getLoadedExtensions()) { for (Extension extension : this.extensionLoader.getLoadedExtensions()) {
@@ -666,6 +666,26 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike, Regist
this.onReload.append(position, task); this.onReload.append(position, task);
} }
/**
* Add new task to run on createTasks.
*
* @param task The task.
*/
public final void onCreateTasks(@NotNull final Runnable task) {
this.onCreateTasks(LifecyclePosition.END, task);
}
/**
* Add new task to run on createTasks.
*
* @param position The position to run the task.
* @param task The task.
*/
public final void onCreateTasks(@NotNull final LifecyclePosition position,
@NotNull final Runnable task) {
this.onCreateTasks.append(position, task);
}
/** /**
* Reload the plugin and return the time taken to reload. * Reload the plugin and return the time taken to reload.
* *