* 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,11 +730,14 @@ public class HumanPlayer extends PlayerImpl {
}
private boolean checkPassStep(Game game) {
if (playerId.equals(game.getActivePlayerId())) {
return !this.getUserData().getUserSkipPrioritySteps().getYourTurn().isPhaseStepSet(game.getStep().getType());
} else {
return !this.getUserData().getUserSkipPrioritySteps().getOpponentTurn().isPhaseStepSet(game.getStep().getType());
if (game.getStep() != null) {
if (playerId.equals(game.getActivePlayerId())) {
return !this.getUserData().getUserSkipPrioritySteps().getYourTurn().isPhaseStepSet(game.getStep().getType());
} else {
return !this.getUserData().getUserSkipPrioritySteps().getOpponentTurn().isPhaseStepSet(game.getStep().getType());
}
}
return true;
}
@Override

View file

@ -567,7 +567,7 @@ public class TableController {
String creator = null;
StringBuilder opponent = new StringBuilder();
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());
if (user != null) {
user.ccGameStarted(match.getGame().getId(), entry.getValue());

View file

@ -45,6 +45,7 @@ import mage.constants.ColoredManaSymbol;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.ExileZone;
import mage.game.Game;
import mage.players.Player;
import mage.util.CardUtil;
@ -139,7 +140,11 @@ class BomatCourierReturnEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
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;
}

View file

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

View file

@ -118,20 +118,19 @@ class FoodChainManaEffect extends ManaEffect {
ChoiceColor choice = new ChoiceColor();
controller.choose(Outcome.PutManaInPool, choice, game);
ObjectColor chosenColor = choice.getColor();
if (chosenColor == null) {
return false;
}
Mana mana = null;
if (chosenColor.isBlack()) {
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();
}
else if (chosenColor.isRed()) {
} else if (chosenColor.isRed()) {
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();
}
else if (chosenColor.isWhite()) {
} else if (chosenColor.isWhite()) {
mana = new FoodChainManaBuilder().setMana(Mana.WhiteMana(manaCostExiled + 1), source, game).build();
}
if (mana != null) {

View file

@ -996,6 +996,10 @@ public abstract class PlayerImpl implements Player, Serializable {
Zone fromZone = game.getState().getZone(card.getMainCard().getId());
card.cast(game, fromZone, ability, playerId);
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
if (ability.getSourceId().equals(getCastSourceIdWithAlternateMana())) {
Ability spellAbility = spell.getSpellAbility();