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 463a83cb..ec714780 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 @@ -152,6 +152,31 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { @Nullable private final ProxyFactory proxyFactory; + /** + * The tasks to run on enable. + */ + private final List onEnable = new ArrayList<>(); + + /** + * The tasks to run on disable. + */ + private final List onDisable = new ArrayList<>(); + + /** + * The tasks to run on reload. + */ + private final List onReload = new ArrayList<>(); + + /** + * The tasks to run on load. + */ + private final List onLoad = new ArrayList<>(); + + /** + * The tasks to run after load. + */ + private final List afterLoad = new ArrayList<>(); + /** * Create a new plugin. *

@@ -414,10 +439,20 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { } this.handleEnable(); + this.onEnable.forEach(Runnable::run); this.getLogger().info(""); } + /** + * Add new task to run on enable. + * + * @param task The task. + */ + public final void onEnable(@NotNull final Runnable task) { + this.onEnable.add(task); + } + /** * Default code to be executed on plugin disable. */ @@ -429,6 +464,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { this.getScheduler().cancelAll(); this.handleDisable(); + this.onDisable.forEach(Runnable::run); if (this.isSupportingExtensions()) { this.getExtensionLoader().unloadExtensions(); @@ -438,6 +474,15 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { Eco.get().clean(this); } + /** + * Add new task to run on disable. + * + * @param task The task. + */ + public final void onDisable(@NotNull final Runnable task) { + this.onDisable.add(task); + } + /** * Default code to be executed on plugin load. */ @@ -446,6 +491,16 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { super.onLoad(); this.handleLoad(); + this.onLoad.forEach(Runnable::run); + } + + /** + * Add new task to run on load. + * + * @param task The task. + */ + public final void onLoad(@NotNull final Runnable task) { + this.onLoad.add(task); } /** @@ -478,6 +533,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { } this.handleAfterLoad(); + this.afterLoad.forEach(Runnable::run); this.reload(); @@ -488,6 +544,15 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { this.getLogger().info("Loaded " + this.color + this.getName()); } + /** + * Add new task to run after load. + * + * @param task The task. + */ + public final void afterLoad(@NotNull final Runnable task) { + this.afterLoad.add(task); + } + /** * Reload the plugin. */ @@ -499,12 +564,22 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike { this.getConfigHandler().callUpdate(); // Call twice to fix issues this.handleReload(); + this.onReload.forEach(Runnable::run); for (Extension extension : this.extensionLoader.getLoadedExtensions()) { extension.handleReload(); } } + /** + * Add new task to run on enable. + * + * @param task The task. + */ + public final void onReload(@NotNull final Runnable task) { + this.onReload.add(task); + } + /** * Reload the plugin and return the time taken to reload. *