* Fixed some possible null pointer exceptions.

This commit is contained in:
LevelX2 2016-09-20 23:40:25 +02:00
parent ab352100f1
commit c82d6b5566
6 changed files with 171 additions and 160 deletions

View file

@ -730,12 +730,15 @@ public class HumanPlayer extends PlayerImpl {
} }
private boolean checkPassStep(Game game) { private boolean checkPassStep(Game game) {
if (game.getStep() != null) {
if (playerId.equals(game.getActivePlayerId())) { if (playerId.equals(game.getActivePlayerId())) {
return !this.getUserData().getUserSkipPrioritySteps().getYourTurn().isPhaseStepSet(game.getStep().getType()); return !this.getUserData().getUserSkipPrioritySteps().getYourTurn().isPhaseStepSet(game.getStep().getType());
} else { } else {
return !this.getUserData().getUserSkipPrioritySteps().getOpponentTurn().isPhaseStepSet(game.getStep().getType()); return !this.getUserData().getUserSkipPrioritySteps().getOpponentTurn().isPhaseStepSet(game.getStep().getType());
} }
} }
return true;
}
@Override @Override
public TriggeredAbility chooseTriggeredAbility(List<TriggeredAbility> abilities, Game game) { public TriggeredAbility chooseTriggeredAbility(List<TriggeredAbility> abilities, Game game) {

View file

@ -567,7 +567,7 @@ public class TableController {
String creator = null; String creator = null;
StringBuilder opponent = new StringBuilder(); StringBuilder opponent = new StringBuilder();
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) { // no AI players for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) { // no AI players
if (!match.getPlayer(entry.getValue()).hasQuit()) { if (match.getPlayer(entry.getValue()) != null && !match.getPlayer(entry.getValue()).hasQuit()) {
User user = UserManager.getInstance().getUser(entry.getKey()); User user = UserManager.getInstance().getUser(entry.getKey());
if (user != null) { if (user != null) {
user.ccGameStarted(match.getGame().getId(), entry.getValue()); user.ccGameStarted(match.getGame().getId(), entry.getValue());

View file

@ -45,6 +45,7 @@ import mage.constants.ColoredManaSymbol;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.ExileZone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil; import mage.util.CardUtil;
@ -139,7 +140,11 @@ class BomatCourierReturnEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
return controller.moveCards(game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source.getSourceId(), true)), Zone.HAND, source, game); ExileZone exileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source.getSourceId(), true));
if (exileZone != null) {
controller.moveCards(exileZone, Zone.HAND, source, game);
}
return true;
} }
return false; return false;
} }

View file

@ -81,7 +81,7 @@ class LostLegacyEffect extends SearchTargetGraveyardHandLibraryForCardNameAndExi
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + NameACardEffect.INFO_KEY); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + NameACardEffect.INFO_KEY);
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source)); Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (targetPlayer != null) { if (targetPlayer != null && cardName != null && !cardName.isEmpty()) {
FilterCard filter = new FilterCard(); FilterCard filter = new FilterCard();
filter.add(new NamePredicate(cardName)); filter.add(new NamePredicate(cardName));
int cardsInHandBefore = targetPlayer.getHand().count(filter, game); int cardsInHandBefore = targetPlayer.getHand().count(filter, game);

View file

@ -118,20 +118,19 @@ class FoodChainManaEffect extends ManaEffect {
ChoiceColor choice = new ChoiceColor(); ChoiceColor choice = new ChoiceColor();
controller.choose(Outcome.PutManaInPool, choice, game); controller.choose(Outcome.PutManaInPool, choice, game);
ObjectColor chosenColor = choice.getColor(); ObjectColor chosenColor = choice.getColor();
if (chosenColor == null) {
return false;
}
Mana mana = null; Mana mana = null;
if (chosenColor.isBlack()) { if (chosenColor.isBlack()) {
mana = new FoodChainManaBuilder().setMana(Mana.BlackMana(manaCostExiled + 1), source, game).build(); mana = new FoodChainManaBuilder().setMana(Mana.BlackMana(manaCostExiled + 1), source, game).build();
} } else if (chosenColor.isBlue()) {
else if (chosenColor.isBlue()) {
mana = new FoodChainManaBuilder().setMana(Mana.BlueMana(manaCostExiled + 1), source, game).build(); mana = new FoodChainManaBuilder().setMana(Mana.BlueMana(manaCostExiled + 1), source, game).build();
} } else if (chosenColor.isRed()) {
else if (chosenColor.isRed()) {
mana = new FoodChainManaBuilder().setMana(Mana.RedMana(manaCostExiled + 1), source, game).build(); mana = new FoodChainManaBuilder().setMana(Mana.RedMana(manaCostExiled + 1), source, game).build();
} } else if (chosenColor.isGreen()) {
else if (chosenColor.isGreen()) {
mana = new FoodChainManaBuilder().setMana(Mana.GreenMana(manaCostExiled + 1), source, game).build(); mana = new FoodChainManaBuilder().setMana(Mana.GreenMana(manaCostExiled + 1), source, game).build();
} } else if (chosenColor.isWhite()) {
else if (chosenColor.isWhite()) {
mana = new FoodChainManaBuilder().setMana(Mana.WhiteMana(manaCostExiled + 1), source, game).build(); mana = new FoodChainManaBuilder().setMana(Mana.WhiteMana(manaCostExiled + 1), source, game).build();
} }
if (mana != null) { if (mana != null) {

View file

@ -996,6 +996,10 @@ public abstract class PlayerImpl implements Player, Serializable {
Zone fromZone = game.getState().getZone(card.getMainCard().getId()); Zone fromZone = game.getState().getZone(card.getMainCard().getId());
card.cast(game, fromZone, ability, playerId); card.cast(game, fromZone, ability, playerId);
Spell spell = game.getStack().getSpell(ability.getId()); Spell spell = game.getStack().getSpell(ability.getId());
if (spell == null) {
logger.error("Got no spell from stack. ability: " + ability.getRule());
return false;
}
// some effects set sourceId to cast without paying mana costs or other costs // some effects set sourceId to cast without paying mana costs or other costs
if (ability.getSourceId().equals(getCastSourceIdWithAlternateMana())) { if (ability.getSourceId().equals(getCastSourceIdWithAlternateMana())) {
Ability spellAbility = spell.getSpellAbility(); Ability spellAbility = spell.getSpellAbility();