From 47c8617d3de0c2fb9c75bdaf9d6553b142d9f08a Mon Sep 17 00:00:00 2001 From: Will FP Date: Thu, 8 Feb 2024 14:22:47 +0000 Subject: [PATCH] Added onCreateTasks --- .../java/com/willfp/eco/core/EcoPlugin.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java b/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java index 88b18f2aa..faa85cbf2 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java +++ b/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java @@ -167,7 +167,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike, Regist /** * The tasks to run on task creation. */ - private final ListMap createTasks = new ListMap<>(); + private final ListMap onCreateTasks = new ListMap<>(); /** * Create a new plugin. @@ -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()) { @@ -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. *