From 423087cc12629f37ce57d248584567097a60b4bd Mon Sep 17 00:00:00 2001 From: Brady Date: Mon, 27 Aug 2018 17:45:31 -0500 Subject: [PATCH] Add a way to hook into Baritone's post-init stage --- src/main/java/baritone/Baritone.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 5642323b..333a9fdb 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -54,11 +54,20 @@ public enum Baritone { private List behaviors; private File dir; + /** + * List of runnables to be called after Baritone has initialized + */ + private List onInitRunnables; + /** * Whether or not Baritone is active */ private boolean active; + Baritone() { + this.onInitRunnables = new ArrayList<>(); + } + public synchronized void init() { if (initialized) { return; @@ -82,6 +91,8 @@ public enum Baritone { this.active = true; this.initialized = true; + + this.onInitRunnables.forEach(Runnable::run); } public final boolean isInitialized() { @@ -120,4 +131,8 @@ public enum Baritone { public final File getDir() { return this.dir; } + + public final void registerInitListener(Runnable runnable) { + this.onInitRunnables.add(runnable); + } }