From 30454f3cab9861b61b6222de8ddf7917dad0a84d Mon Sep 17 00:00:00 2001 From: Hellfish Date: Tue, 21 May 2013 20:51:40 +0000 Subject: [PATCH] *Fixed NPE when spectating AIvAI into game 2+ --- src/main/java/forge/game/MatchController.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/forge/game/MatchController.java b/src/main/java/forge/game/MatchController.java index 25b6cc6d0c0..d44622fc2b5 100644 --- a/src/main/java/forge/game/MatchController.java +++ b/src/main/java/forge/game/MatchController.java @@ -357,13 +357,18 @@ public class MatchController { */ private Player determineFirstTurnPlayer(final GameOutcome lastGameOutcome, final GameState game) { // Only cut/coin toss if it's the first game of the match - Player goesFirst; + Player goesFirst = null; Player humanPlayer = Singletons.getControl().getPlayer(); boolean isFirstGame = lastGameOutcome == null; if (isFirstGame) { goesFirst = seeWhoPlaysFirstDice(game); } else { - goesFirst = lastGameOutcome.isWinner(humanPlayer.getLobbyPlayer()) ? humanPlayer.getOpponent() : humanPlayer; + for(Player p : game.getPlayers()) { + if(lastGameOutcome.isWinner(p.getLobbyPlayer())) { + goesFirst = p.getOpponent(); + break; + } + } } String message = goesFirst + ( isFirstGame ? " has won the coin toss." : " lost the last game."); boolean willPlay = goesFirst.getController().getWillPlayOnFirstTurn(message);