From ea81cd76caef3ae3bd279cddfd0c681808768982 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 14 Nov 2018 14:00:56 -0800 Subject: [PATCH] sigh --- src/api/java/baritone/api/IBaritoneProvider.java | 13 ++++++++++--- src/main/java/baritone/BaritoneProvider.java | 14 ++++---------- src/main/java/baritone/event/GameEventHandler.java | 4 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java index 673a9857..d17e8e00 100644 --- a/src/api/java/baritone/api/IBaritoneProvider.java +++ b/src/api/java/baritone/api/IBaritoneProvider.java @@ -20,7 +20,7 @@ package baritone.api; import baritone.api.cache.IWorldScanner; import net.minecraft.client.entity.EntityPlayerSP; -import java.util.Set; +import java.util.List; /** * @author Leijurv @@ -43,7 +43,7 @@ public interface IBaritoneProvider { * @return All active {@link IBaritone} instances. * @see #getBaritoneForPlayer(EntityPlayerSP) */ - Set getAllBaritones(); + List getAllBaritones(); /** * Provides the {@link IBaritone} instance for a given {@link EntityPlayerSP}. This will likely be @@ -52,7 +52,14 @@ public interface IBaritoneProvider { * @param player The player * @return The {@link IBaritone} instance. */ - IBaritone getBaritoneForPlayer(EntityPlayerSP player); + default IBaritone getBaritoneForPlayer(EntityPlayerSP player) { + for (IBaritone baritone : getAllBaritones()) { + if (player.equals(baritone.getPlayerContext().player())) { + return baritone; + } + } + throw new IllegalStateException("No baritone for player " + player); + } /** * Returns the {@link IWorldScanner} instance. This is not a type returned by diff --git a/src/main/java/baritone/BaritoneProvider.java b/src/main/java/baritone/BaritoneProvider.java index 93f8faed..73e5e6e5 100644 --- a/src/main/java/baritone/BaritoneProvider.java +++ b/src/main/java/baritone/BaritoneProvider.java @@ -21,10 +21,9 @@ import baritone.api.IBaritone; import baritone.api.IBaritoneProvider; import baritone.api.cache.IWorldScanner; import baritone.cache.WorldScanner; -import net.minecraft.client.entity.EntityPlayerSP; import java.util.Collections; -import java.util.Set; +import java.util.List; /** * @author Brady @@ -40,14 +39,9 @@ public final class BaritoneProvider implements IBaritoneProvider { } @Override - public Set getAllBaritones() { - return Collections.singleton(primary); - } - - @Override - public IBaritone getBaritoneForPlayer(EntityPlayerSP player) { - // TODO implement on bot-system branch - return primary; + public List getAllBaritones() { + // TODO return a CopyOnWriteArrayList + return Collections.singletonList(primary); } @Override diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index d2739b38..6fd4665b 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -26,8 +26,8 @@ import baritone.utils.Helper; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; -import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; /** * @author Brady @@ -37,7 +37,7 @@ public final class GameEventHandler implements IGameEventListener, Helper { private final Baritone baritone; - private final List listeners = new ArrayList<>(); + private final List listeners = new CopyOnWriteArrayList<>(); public GameEventHandler(Baritone baritone) { this.baritone = baritone;