Fixed NPE on playerList.getNext usage

This commit is contained in:
Oleg Agafonov 2020-08-25 23:38:51 +04:00
parent f1d2d2fb22
commit 6fa4c0b8f2
7 changed files with 19 additions and 11 deletions

View file

@ -95,7 +95,7 @@ class EyeOfDoomEffect extends OneShotEffect {
}
}
player = playerList.getNext(game, false);
} while (!player.getId().equals(game.getActivePlayerId()));
} while (player != null && !player.getId().equals(game.getActivePlayerId()));
for (Permanent permanent : permanents) {
permanent.addCounters(CounterType.DOOM.createInstance(), source, game);

View file

@ -71,7 +71,7 @@ class TariffEffect extends OneShotEffect {
do {
processPlayer(game, source, player);
player = playerList.getNext(game, false);
} while (!player.getId().equals(game.getActivePlayerId()));
} while (player != null && !player.getId().equals(game.getActivePlayerId()));
return true;
}

View file

@ -81,7 +81,7 @@ class TemptWithReflectionsEffect extends OneShotEffect {
game.informPlayers((player.getLogName() + decision + permanent.getName()));
}
player = playerList.getNext(game, false);
} while (!player.getId().equals(game.getActivePlayerId()));
} while (player != null && !player.getId().equals(game.getActivePlayerId()));
for (UUID playerId : playersSaidYes) {
effect = new CreateTokenCopyTargetEffect(playerId);

View file

@ -77,8 +77,8 @@ class ThievesAuctionEffect extends OneShotEffect {
// Starting with you, each player
PlayerList playerList = game.getState().getPlayersInRange(controller.getId(), game);
Player player = playerList.getCurrent(game);
while (!exiledCards.isEmpty() && !game.hasEnded()) {
if (player != null && player.canRespond()) {
while (player != null && !exiledCards.isEmpty() && !game.hasEnded()) {
if (player.canRespond()) {
// chooses one of the exiled cards
TargetCard target = new TargetCardInExile(new FilterCard());
if (player.choose(Outcome.PutCardInPlay, exiledCards, target, game)) {

View file

@ -39,7 +39,7 @@ public final class MtgJsonCard {
if ("transform".equals(layout)
|| "flip".equals(layout)
|| "adventure".equals(layout)
|| "meld".equals(layout)) { // TODO: remove or keep after mtgjson's meld bug resolve https://github.com/mtgjson/mtgjson/issues/661
|| "meld".equals(layout)) { // mtgjson uses composite names for meld cards, but scryfall uses simple face names
return faceName;
}
return asciiName != null ? asciiName : name;

View file

@ -796,7 +796,9 @@ public abstract class GameImpl implements Game, Serializable {
break;
}
playerByOrder = playerList.getNext(this, true);
state.setPlayerByOrderId(playerByOrder.getId());
if (playerByOrder != null) {
state.setPlayerByOrderId(playerByOrder.getId());
}
}
}
if (checkIfGameIsOver() && !isSimulation()) {
@ -902,7 +904,10 @@ public abstract class GameImpl implements Game, Serializable {
state.getTurn().resumePlay(this, wasPaused);
if (!isPaused() && !checkIfGameIsOver()) {
endOfTurn();
player = playerList.getNext(this, true);
Player nextPlayer = playerList.getNext(this, true);
if (nextPlayer != null) {
player = nextPlayer;
}
state.setTurnNum(state.getTurnNum() + 1);
}
}

View file

@ -1234,25 +1234,28 @@ public class Combat implements Serializable, Copyable<Combat> {
Player attackingPlayer = game.getPlayer(attackingPlayerId);
if (attackingPlayer != null) {
PlayerList players;
Player opponent;
switch (game.getAttackOption()) {
case LEFT:
players = game.getState().getPlayerList(attackingPlayerId);
while (attackingPlayer.isInGame()) {
Player opponent = players.getNext(game, false);
opponent = players.getNext(game, false);
while (opponent != null && attackingPlayer.isInGame()) {
if (attackingPlayer.hasOpponent(opponent.getId(), game)) {
attackablePlayers.add(opponent.getId());
break;
}
opponent = players.getNext(game, false);
}
break;
case RIGHT:
players = game.getState().getPlayerList(attackingPlayerId);
opponent = players.getPrevious(game);
while (attackingPlayer.isInGame()) {
Player opponent = players.getPrevious(game);
if (attackingPlayer.hasOpponent(opponent.getId(), game)) {
attackablePlayers.add(opponent.getId());
break;
}
opponent = players.getPrevious(game);
}
break;
case MULTIPLE: