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

View file

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

View file

@ -45,6 +45,7 @@ import mage.filter.predicate.mageobject.ConvertedManaCostPredicate;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import org.apache.log4j.Logger;
/** /**
* *
@ -77,7 +78,7 @@ class BringToLightEffect extends OneShotEffect {
public BringToLightEffect() { public BringToLightEffect() {
super(Outcome.PlayForFree); super(Outcome.PlayForFree);
this.staticText = "<i>Converge</i> &mdash; Search your library for a creature, instant, or sorcery card with converted mana " 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"; + "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); controller.searchLibrary(target, game);
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game); Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) { if (card != null) {
controller.moveCards(card, null, Zone.EXILED, source, game); controller.moveCards(card, Zone.EXILED, source, game);
} }
controller.shuffleLibrary(game); controller.shuffleLibrary(game);
if (card != null) { if (card != null) {
if (controller.chooseUse(outcome, "Cast " + card.getName() + " without paying its mana cost?", source, game)) { if (controller.chooseUse(outcome, "Cast " + card.getName() + " without paying its mana cost?", source, game)) {
controller.cast(card.getSpellAbility(), game, true); 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; return true;

View file

@ -94,7 +94,7 @@ class RingsOfBrighthearthTriggeredAbility extends TriggeredAbilityImpl {
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (event.getPlayerId().equals(getControllerId())) { if (event.getPlayerId().equals(getControllerId())) {
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId()); 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 effect = this.getEffects().get(0);
effect.setValue("stackAbility", stackAbility.getStackAbility()); effect.setValue("stackAbility", stackAbility.getStackAbility());
return true; return true;

View file

@ -28,11 +28,6 @@
package mage.sets.mirrodin; package mage.sets.mirrodin;
import java.util.UUID; 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.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
@ -41,6 +36,10 @@ import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; 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.Filter;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.CardTypePredicate; import mage.filter.predicate.mageobject.CardTypePredicate;
@ -50,6 +49,7 @@ import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetCard; import mage.target.TargetCard;
import mage.util.CardUtil; import mage.util.CardUtil;
import org.apache.log4j.Logger;
/** /**
* *
@ -84,7 +84,8 @@ public class IsochronScepter extends CardImpl {
class IsochronScepterImprintEffect extends OneShotEffect { class IsochronScepterImprintEffect extends OneShotEffect {
private static final FilterCard filter = new FilterCard("instant card with converted mana cost 2 or less from your hand"); private static final FilterCard filter = new FilterCard("instant card with converted mana cost 2 or less from your hand");
static {
static {
filter.add(new CardTypePredicate(CardType.INSTANT)); filter.add(new CardTypePredicate(CardType.INSTANT));
filter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.LessThan, 3)); filter.add(new ConvertedManaCostPredicate(Filter.ComparisonType.LessThan, 3));
} }
@ -109,7 +110,7 @@ class IsochronScepterImprintEffect extends OneShotEffect {
&& controller.choose(Outcome.Benefit, controller.getHand(), target, game)) { && controller.choose(Outcome.Benefit, controller.getHand(), target, game)) {
Card card = controller.getHand().get(target.getFirstTarget(), game); Card card = controller.getHand().get(target.getFirstTarget(), game);
if (card != null) { 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()); Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) { if (permanent != null) {
permanent.imprint(card.getId(), game); permanent.imprint(card.getId(), game);
@ -121,7 +122,7 @@ class IsochronScepterImprintEffect extends OneShotEffect {
return true; return true;
} }
return false; return false;
} }
@java.lang.Override @java.lang.Override
@ -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)) { 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()); Card copiedCard = game.copyCard(imprintedInstant, source, source.getControllerId());
if (copiedCard != null) { if (copiedCard != null) {
game.getExile().add(source.getSourceId(), "",copiedCard); game.getExile().add(source.getSourceId(), "", copiedCard);
game.getState().setZone(copiedCard.getId(), Zone.EXILED); game.getState().setZone(copiedCard.getId(), Zone.EXILED);
if (controller.chooseUse(outcome, "Cast the copied card without paying mana cost?", source, game)) { if (controller.chooseUse(outcome, "Cast the copied card without paying mana cost?", source, game)) {
controller.cast(copiedCard.getSpellAbility(), game, true); 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 * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.sets.scarsofmirrodin; package mage.sets.scarsofmirrodin;
import mage.constants.CardType; import java.util.UUID;
import mage.constants.Rarity;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAbility; import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Layer; import mage.constants.Layer;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.SubLayer; import mage.constants.SubLayer;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
import mage.target.Target; import mage.target.Target;
import mage.target.common.TargetCreaturePermanent;
/** /**
* @author ayratn * @author ayratn
@ -60,7 +58,7 @@ public class QuicksilverGargantuan extends CardImpl {
this.power = new MageInt(7); this.power = new MageInt(7);
this.toughness = new MageInt(7); this.toughness = new MageInt(7);
Ability ability = new EntersBattlefieldAbility(new QuicksilverGargantuanCopyEffect(), Ability ability = new EntersBattlefieldAbility(new QuicksilverGargantuanCopyEffect(),
"You may have {this} enter the battlefield as a copy of any creature on the battlefield, except it's still 7/7"); "You may have {this} enter the battlefield as a copy of any creature on the battlefield, except it's still 7/7");
Target target = new TargetCreaturePermanent(); Target target = new TargetCreaturePermanent();
target.setNotTarget(true); target.setNotTarget(true);
@ -81,7 +79,7 @@ public class QuicksilverGargantuan extends CardImpl {
public QuicksilverGargantuanCopyEffect() { public QuicksilverGargantuanCopyEffect() {
super(Duration.WhileOnBattlefield, Layer.CopyEffects_1, SubLayer.NA, Outcome.BecomeCreature); super(Duration.WhileOnBattlefield, Layer.CopyEffects_1, SubLayer.NA, Outcome.BecomeCreature);
staticText = "You may have {this} enter the battlefield as a copy of any creature on the battlefield, except it's still 7/7"; staticText = "You may have {this} enter the battlefield as a copy of any creature on the battlefield, except it's still 7/7";
} }
public QuicksilverGargantuanCopyEffect(final QuicksilverGargantuanCopyEffect effect) { public QuicksilverGargantuanCopyEffect(final QuicksilverGargantuanCopyEffect effect) {
@ -91,30 +89,35 @@ public class QuicksilverGargantuan extends CardImpl {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getFirstTarget()); Card card = game.getCard(source.getFirstTarget());
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanentEntering(source.getSourceId());
permanent.setName(card.getName()); if (permanent == null) {
permanent.getColor(game).setColor(card.getColor(game)); permanent = game.getPermanent(source.getSourceId());
permanent.getManaCost().clear();
permanent.getManaCost().add(card.getManaCost());
permanent.getCardType().clear();
for (CardType type : card.getCardType()) {
permanent.getCardType().add(type);
} }
permanent.getSubtype().clear(); if (permanent != null) {
for (String type : card.getSubtype()) { permanent.setName(card.getName());
permanent.getSubtype().add(type); permanent.getColor(game).setColor(card.getColor(game));
permanent.getManaCost().clear();
permanent.getManaCost().add(card.getManaCost());
permanent.getCardType().clear();
for (CardType type : card.getCardType()) {
permanent.getCardType().add(type);
}
permanent.getSubtype().clear();
for (String type : card.getSubtype()) {
permanent.getSubtype().add(type);
}
permanent.getSupertype().clear();
for (String type : card.getSupertype()) {
permanent.getSupertype().add(type);
}
permanent.setExpansionSetCode(card.getExpansionSetCode());
permanent.getAbilities().clear();
for (Ability ability : card.getAbilities()) {
permanent.addAbility(ability, game);
}
return true;
} }
permanent.getSupertype().clear(); return false;
for (String type : card.getSupertype()) {
permanent.getSupertype().add(type);
}
permanent.setExpansionSetCode(card.getExpansionSetCode());
permanent.getAbilities().clear();
for (Ability ability : card.getAbilities()) {
permanent.addAbility(ability, game);
}
return true;
} }
@Override @Override

View file

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

View file

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

View file

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

View file

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

View file

@ -129,7 +129,9 @@ public abstract class GameCommanderImpl extends GameImpl {
if (!mulliganedCards.containsKey(playerId)) { if (!mulliganedCards.containsKey(playerId)) {
mulliganedCards.put(playerId, new CardsImpl()); 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); card.setFaceDown(true, this);
mulliganedCards.get(playerId).add(card); mulliganedCards.get(playerId).add(card);
} }
@ -168,7 +170,9 @@ public abstract class GameCommanderImpl extends GameImpl {
if (player != null && mulliganedCards.containsKey(playerId)) { if (player != null && mulliganedCards.containsKey(playerId)) {
for (Card card : mulliganedCards.get(playerId).getCards(this)) { for (Card card : mulliganedCards.get(playerId).getCards(this)) {
if (card != null) { 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); card.setFaceDown(false, this);
} }
} }

View file

@ -59,7 +59,7 @@ public class UserData implements Serializable {
} }
public static UserData getDefaultUserDataView() { 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) { public void setGroupId(int groupId) {
@ -166,4 +166,7 @@ public class UserData implements Serializable {
this.autoOrderTrigger = autoOrderTrigger; this.autoOrderTrigger = autoOrderTrigger;
} }
public static String getDefaultFlagName() {
return "world.png";
}
} }