diff --git a/src/api/java/baritone/api/BaritoneAPI.java b/src/api/java/baritone/api/BaritoneAPI.java index dec7ec13..cba66ddc 100644 --- a/src/api/java/baritone/api/BaritoneAPI.java +++ b/src/api/java/baritone/api/BaritoneAPI.java @@ -19,6 +19,7 @@ package baritone.api; import baritone.api.behavior.*; import baritone.api.cache.IWorldProvider; +import baritone.api.event.listener.IGameEventListener; import java.util.Iterator; import java.util.ServiceLoader; @@ -71,4 +72,8 @@ public final class BaritoneAPI { public static IWorldProvider getWorldProvider() { return baritone.getWorldProvider(); } + + public static void registerEventListener(IGameEventListener listener) { + baritone.registerEventListener(listener); + } } diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java index 52dae153..aa20979b 100644 --- a/src/api/java/baritone/api/IBaritoneProvider.java +++ b/src/api/java/baritone/api/IBaritoneProvider.java @@ -19,6 +19,7 @@ package baritone.api; import baritone.api.behavior.*; import baritone.api.cache.IWorldProvider; +import baritone.api.event.listener.IGameEventListener; /** * @author Brady @@ -67,4 +68,11 @@ public interface IBaritoneProvider { * @return The {@link IWorldProvider} instance */ IWorldProvider getWorldProvider(); + + /** + * Registers a {@link IGameEventListener} with Baritone's "event bus". + * + * @param listener The listener + */ + void registerEventListener(IGameEventListener listener); } diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index b7904d00..9b887032 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -21,7 +21,6 @@ import baritone.api.BaritoneAPI; import baritone.api.Settings; import baritone.api.event.listener.IGameEventListener; import baritone.behavior.*; -import baritone.cache.WorldProvider; import baritone.event.GameEventHandler; import baritone.utils.BaritoneAutoTest; import baritone.utils.InputOverrideHandler; @@ -36,7 +35,6 @@ import java.util.concurrent.Executor; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import java.util.function.Consumer; /** * @author Brady @@ -61,19 +59,13 @@ public enum Baritone { private File dir; private ThreadPoolExecutor threadPool; - - /** - * List of consumers to be called after Baritone has initialized - */ - private List> onInitConsumers; - /** * Whether or not Baritone is active */ private boolean active; Baritone() { - this.onInitConsumers = new ArrayList<>(); + this.gameEventHandler = new GameEventHandler(); } public synchronized void init() { @@ -81,7 +73,6 @@ public enum Baritone { return; } this.threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); - this.gameEventHandler = new GameEventHandler(); this.inputOverrideHandler = new InputOverrideHandler(); // Acquire the "singleton" instance of the settings directly from the API @@ -109,8 +100,6 @@ public enum Baritone { this.active = true; this.initialized = true; - - this.onInitConsumers.forEach(consumer -> consumer.accept(this)); } public boolean isInitialized() { @@ -157,8 +146,4 @@ public enum Baritone { public File getDir() { return this.dir; } - - public void registerInitListener(Consumer runnable) { - this.onInitConsumers.add(runnable); - } } diff --git a/src/main/java/baritone/BaritoneProvider.java b/src/main/java/baritone/BaritoneProvider.java index 370a398e..eb6bf27a 100644 --- a/src/main/java/baritone/BaritoneProvider.java +++ b/src/main/java/baritone/BaritoneProvider.java @@ -20,6 +20,7 @@ package baritone; import baritone.api.IBaritoneProvider; import baritone.api.behavior.*; import baritone.api.cache.IWorldProvider; +import baritone.api.event.listener.IGameEventListener; import baritone.behavior.*; import baritone.cache.WorldProvider; @@ -58,4 +59,9 @@ public final class BaritoneProvider implements IBaritoneProvider { public IWorldProvider getWorldProvider() { return WorldProvider.INSTANCE; } + + @Override + public void registerEventListener(IGameEventListener listener) { + Baritone.INSTANCE.registerEventListener(listener); + } }