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