Skip to content

Commit

Permalink
Added onCreateTasks
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Feb 8, 2024
1 parent c977cb2 commit 47c8617
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike, Regist
/**
* 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.
Expand Down Expand Up @@ -638,7 +638,7 @@ public final void reload(final boolean cancelTasks) {
this.handleLifecycle(this.onReload, this::handleReload);

if (cancelTasks) {
this.handleLifecycle(this.createTasks, this::createTasks);
this.handleLifecycle(this.onCreateTasks, this::createTasks);
}

for (Extension extension : this.extensionLoader.getLoadedExtensions()) {
Expand Down Expand Up @@ -666,6 +666,26 @@ public final void onReload(@NotNull final LifecyclePosition position,
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.
*
Expand Down

0 comments on commit 47c8617

Please sign in to comment.