Checked objects possible to cause null pointer exceptions. Added some logging.

This commit is contained in:
LevelX2 2015-10-31 11:55:20 +01:00
parent c1d6703e71
commit a5d7ca83d7
12 changed files with 94 additions and 66 deletions

View file

@ -30,6 +30,7 @@ package mage.view;
import java.io.Serializable;
import java.util.UUID;
import mage.game.Seat;
import mage.players.net.UserData;
/**
*
@ -48,7 +49,11 @@ public class SeatView implements Serializable {
if (seat.getPlayer() != null) {
this.playerId = seat.getPlayer().getId();
this.playerName = seat.getPlayer().getName();
if (seat.getPlayer().getUserData() == null) {
this.flagName = UserData.getDefaultFlagName();
} else {
this.flagName = seat.getPlayer().getUserData().getFlagName();
}
} else {
// Empty seat
this.playerName = "";

View file

@ -228,15 +228,17 @@ class TableListSorter implements Comparator<Table> {
@Override
public int compare(Table one, Table two) {
if (!one.getState().equals(TableState.SIDEBOARDING) && !one.getState().equals(TableState.DUELING)) {
if (one.getState() != null && two.getState() != null) {
if (!TableState.SIDEBOARDING.equals(one.getState()) && !TableState.DUELING.equals(one.getState())) {
if (one.getState().compareTo(two.getState()) != 0) {
return one.getState().compareTo(two.getState());
}
} else if (!two.getState().equals(TableState.SIDEBOARDING) && !two.getState().equals(TableState.DUELING)) {
} else if (!TableState.SIDEBOARDING.equals(two.getState()) && !TableState.DUELING.equals(two.getState())) {
if (one.getState().compareTo(two.getState()) != 0) {
return one.getState().compareTo(two.getState());
}
}
}
if (two.getEndTime() != null) {
if (one.getEndTime() == null) {
return 1;

View file

@ -45,6 +45,7 @@ import mage.filter.predicate.mageobject.ConvertedManaCostPredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInLibrary;
import org.apache.log4j.Logger;
/**
*
@ -77,7 +78,7 @@ class BringToLightEffect extends OneShotEffect {
public BringToLightEffect() {
super(Outcome.PlayForFree);
this.staticText = "<i>Converge</i> &mdash; Search your library for a creature, instant, or sorcery card with converted mana "
+ "cost less than or equal to the number of colors of mana spent to cast Bring to Light, exile that card, "
+ "cost less than or equal to the number of colors of mana spent to cast {this}, exile that card, "
+ "then shuffle your library. You may cast that card without paying its mana cost";
}
@ -102,12 +103,16 @@ class BringToLightEffect extends OneShotEffect {
controller.searchLibrary(target, game);
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, null, Zone.EXILED, source, game);
controller.moveCards(card, Zone.EXILED, source, game);
}
controller.shuffleLibrary(game);
if (card != null) {
if (controller.chooseUse(outcome, "Cast " + card.getName() + " without paying its mana cost?", source, game)) {
if (card.getSpellAbility() != null) {
controller.cast(card.getSpellAbility(), game, true);
} else {
Logger.getLogger(BringToLightEffect.class).error("Bring to Light: spellAbility == null " + card.getName());
}
}
}
return true;

View file

@ -94,7 +94,7 @@ class RingsOfBrighthearthTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getPlayerId().equals(getControllerId())) {
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (!(stackAbility.getStackAbility() instanceof ManaAbility)) {
if (stackAbility != null && !(stackAbility.getStackAbility() instanceof ManaAbility)) {
Effect effect = this.getEffects().get(0);
effect.setValue("stackAbility", stackAbility.getStackAbility());
return true;

View file

@ -28,11 +28,6 @@
package mage.sets.mirrodin;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
@ -41,6 +36,10 @@ import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.Filter;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.CardTypePredicate;
@ -50,6 +49,7 @@ import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetCard;
import mage.util.CardUtil;
import org.apache.log4j.Logger;
/**
*
@ -84,6 +84,7 @@ public class IsochronScepter extends CardImpl {
class IsochronScepterImprintEffect extends OneShotEffect {
private static final FilterCard filter = new FilterCard("instant card with converted mana cost 2 or less from your hand");
static {
filter.add(new CardTypePredicate(CardType.INSTANT));
filter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.LessThan, 3));
@ -109,7 +110,7 @@ class IsochronScepterImprintEffect extends OneShotEffect {
&& controller.choose(Outcome.Benefit, controller.getHand(), target, game)) {
Card card = controller.getHand().get(target.getFirstTarget(), game);
if (card != null) {
controller.moveCardToExileWithInfo(card, source.getSourceId(), sourcePermanent.getIdName() +" (Imprint)", source.getSourceId(), game, Zone.HAND, true);
controller.moveCardToExileWithInfo(card, source.getSourceId(), sourcePermanent.getIdName() + " (Imprint)", source.getSourceId(), game, Zone.HAND, true);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
permanent.imprint(card.getId(), game);
@ -158,10 +159,14 @@ class IsochronScepterCopyEffect extends OneShotEffect {
if (controller.chooseUse(outcome, new StringBuilder("Create a copy of ").append(imprintedInstant.getName()).append("?").toString(), source, game)) {
Card copiedCard = game.copyCard(imprintedInstant, source, source.getControllerId());
if (copiedCard != null) {
game.getExile().add(source.getSourceId(), "",copiedCard);
game.getExile().add(source.getSourceId(), "", copiedCard);
game.getState().setZone(copiedCard.getId(), Zone.EXILED);
if (controller.chooseUse(outcome, "Cast the copied card without paying mana cost?", source, game)) {
if (copiedCard.getSpellAbility() != null) {
controller.cast(copiedCard.getSpellAbility(), game, true);
} else {
Logger.getLogger(IsochronScepterCopyEffect.class).error("Isochron Scepter: spell ability == null " + copiedCard.getName());
}
}
}
}

View file

@ -25,27 +25,25 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.sets.scarsofmirrodin;
import mage.constants.CardType;
import mage.constants.Rarity;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.SubLayer;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
import mage.target.Target;
import mage.target.common.TargetCreaturePermanent;
/**
* @author ayratn
@ -91,7 +89,11 @@ public class QuicksilverGargantuan extends CardImpl {
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getFirstTarget());
Permanent permanent = game.getPermanent(source.getSourceId());
Permanent permanent = game.getPermanentEntering(source.getSourceId());
if (permanent == null) {
permanent = game.getPermanent(source.getSourceId());
}
if (permanent != null) {
permanent.setName(card.getName());
permanent.getColor(game).setColor(card.getColor(game));
permanent.getManaCost().clear();
@ -113,9 +115,10 @@ public class QuicksilverGargantuan extends CardImpl {
for (Ability ability : card.getAbilities()) {
permanent.addAbility(ability, game);
}
return true;
}
return false;
}
@Override
public QuicksilverGargantuanCopyEffect copy() {

View file

@ -36,7 +36,6 @@ import mage.abilities.effects.common.ManaEffect;
import mage.abilities.mana.SimpleManaAbility;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
@ -83,11 +82,11 @@ class DoublingCubeEffect extends ManaEffect {
@Override
public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId());
if (you == null) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
ManaPool pool = you.getManaPool();
ManaPool pool = controller.getManaPool();
int blackMana = pool.getBlack();
int whiteMana = pool.getWhite();
int blueMana = pool.getBlue();
@ -105,10 +104,9 @@ class DoublingCubeEffect extends ManaEffect {
return null;
}
@Override
public DoublingCubeEffect copy() {
return new DoublingCubeEffect(this);
}
}
}

View file

@ -259,7 +259,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
@Override
public String toString() {
StringBuilder sbMana = threadLocalBuilder.get();
StringBuilder sbMana = new StringBuilder();
if (colorless > 0) {
sbMana.append("{").append(Integer.toString(colorless)).append("}");
}

View file

@ -30,8 +30,11 @@ public class AnotherCreatureEntersBattlefieldTriggeredAbility extends TriggeredA
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId() != this.getSourceId()) {
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent.getCardType().contains(CardType.CREATURE)) {
Permanent permanent = game.getPermanentEntering(event.getTargetId());
if (permanent == null) {
permanent = game.getPermanent(event.getTargetId());
}
if (permanent != null && permanent.getCardType().contains(CardType.CREATURE)) {
return true;
}
}

View file

@ -46,7 +46,7 @@ public class ColorPredicate implements Predicate<MageObject> {
@Override
public boolean apply(MageObject input, Game game) {
return input.getColor(game).contains(color);
return color != null && input.getColor(game).contains(color);
}
@Override

View file

@ -129,7 +129,9 @@ public abstract class GameCommanderImpl extends GameImpl {
if (!mulliganedCards.containsKey(playerId)) {
mulliganedCards.put(playerId, new CardsImpl());
}
card.moveToExile(null, "", null, this);
player.getHand().remove(card);
getExile().add(card);
getState().setZone(card.getId(), Zone.EXILED);
card.setFaceDown(true, this);
mulliganedCards.get(playerId).add(card);
}
@ -168,7 +170,9 @@ public abstract class GameCommanderImpl extends GameImpl {
if (player != null && mulliganedCards.containsKey(playerId)) {
for (Card card : mulliganedCards.get(playerId).getCards(this)) {
if (card != null) {
card.moveToZone(Zone.LIBRARY, null, this, false);
getExile().removeCard(card, this);
player.getLibrary().putOnTop(card, this);
getState().setZone(card.getId(), Zone.LIBRARY);
card.setFaceDown(false, this);
}
}

View file

@ -59,7 +59,7 @@ public class UserData implements Serializable {
}
public static UserData getDefaultUserDataView() {
return new UserData(UserGroup.DEFAULT, 0, false, false, true, null, "world.png", false, true, true, false, false, false);
return new UserData(UserGroup.DEFAULT, 0, false, false, true, null, getDefaultFlagName(), false, true, true, false, false, false);
}
public void setGroupId(int groupId) {
@ -166,4 +166,7 @@ public class UserData implements Serializable {
this.autoOrderTrigger = autoOrderTrigger;
}
public static String getDefaultFlagName() {
return "world.png";
}
}