This commit is contained in:
Leijurv 2018-11-14 14:00:56 -08:00
parent c3a3670785
commit ea81cd76ca
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 16 additions and 15 deletions

View File

@ -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<IBaritone> getAllBaritones();
List<IBaritone> 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

View File

@ -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<IBaritone> getAllBaritones() {
return Collections.singleton(primary);
}
@Override
public IBaritone getBaritoneForPlayer(EntityPlayerSP player) {
// TODO implement on bot-system branch
return primary;
public List<IBaritone> getAllBaritones() {
// TODO return a CopyOnWriteArrayList
return Collections.singletonList(primary);
}
@Override

View File

@ -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<IGameEventListener> listeners = new ArrayList<>();
private final List<IGameEventListener> listeners = new CopyOnWriteArrayList<>();
public GameEventHandler(Baritone baritone) {
this.baritone = baritone;