Make Baritone initialization listeners consumers

This commit is contained in:
Brady 2018-09-02 14:18:11 -05:00
parent e8b108fde8
commit 115b8553b2
No known key found for this signature in database
GPG Key ID: 73A788379A197567
1 changed files with 7 additions and 6 deletions

View File

@ -28,6 +28,7 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.function.Consumer;
/** /**
* @author Brady * @author Brady
@ -52,9 +53,9 @@ public enum Baritone {
private File dir; private File dir;
/** /**
* List of runnables to be called after Baritone has initialized * List of consumers to be called after Baritone has initialized
*/ */
private List<Runnable> onInitRunnables; private List<Consumer<Baritone>> onInitConsumers;
/** /**
* Whether or not Baritone is active * Whether or not Baritone is active
@ -62,7 +63,7 @@ public enum Baritone {
private boolean active; private boolean active;
Baritone() { Baritone() {
this.onInitRunnables = new ArrayList<>(); this.onInitConsumers = new ArrayList<>();
} }
public synchronized void init() { public synchronized void init() {
@ -91,7 +92,7 @@ public enum Baritone {
this.active = true; this.active = true;
this.initialized = true; this.initialized = true;
this.onInitRunnables.forEach(Runnable::run); this.onInitConsumers.forEach(consumer -> consumer.accept(this));
} }
public final boolean isInitialized() { public final boolean isInitialized() {
@ -131,7 +132,7 @@ public enum Baritone {
return this.dir; return this.dir;
} }
public final void registerInitListener(Runnable runnable) { public final void registerInitListener(Consumer<Baritone> runnable) {
this.onInitRunnables.add(runnable); this.onInitConsumers.add(runnable);
} }
} }