mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
Checked objects possible to cause null pointer exceptions. Added some logging.
This commit is contained in:
parent
c1d6703e71
commit
a5d7ca83d7
12 changed files with 94 additions and 66 deletions
|
@ -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();
|
||||||
|
if (seat.getPlayer().getUserData() == null) {
|
||||||
|
this.flagName = UserData.getDefaultFlagName();
|
||||||
|
} else {
|
||||||
this.flagName = seat.getPlayer().getUserData().getFlagName();
|
this.flagName = seat.getPlayer().getUserData().getFlagName();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Empty seat
|
// Empty seat
|
||||||
this.playerName = "";
|
this.playerName = "";
|
||||||
|
|
|
@ -228,15 +228,17 @@ 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 (!TableState.SIDEBOARDING.equals(one.getState()) && !TableState.DUELING.equals(one.getState())) {
|
||||||
if (one.getState().compareTo(two.getState()) != 0) {
|
if (one.getState().compareTo(two.getState()) != 0) {
|
||||||
return one.getState().compareTo(two.getState());
|
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) {
|
if (one.getState().compareTo(two.getState()) != 0) {
|
||||||
return one.getState().compareTo(two.getState());
|
return one.getState().compareTo(two.getState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (two.getEndTime() != null) {
|
if (two.getEndTime() != null) {
|
||||||
if (one.getEndTime() == null) {
|
if (one.getEndTime() == null) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -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> — Search your library for a creature, instant, or sorcery card with converted mana "
|
this.staticText = "<i>Converge</i> — 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)) {
|
||||||
|
if (card.getSpellAbility() != null) {
|
||||||
controller.cast(card.getSpellAbility(), game, true);
|
controller.cast(card.getSpellAbility(), game, true);
|
||||||
|
} else {
|
||||||
|
Logger.getLogger(BringToLightEffect.class).error("Bring to Light: spellAbility == null " + card.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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,6 +84,7 @@ 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);
|
||||||
|
@ -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)) {
|
||||||
|
if (copiedCard.getSpellAbility() != null) {
|
||||||
controller.cast(copiedCard.getSpellAbility(), game, true);
|
controller.cast(copiedCard.getSpellAbility(), game, true);
|
||||||
|
} else {
|
||||||
|
Logger.getLogger(IsochronScepterCopyEffect.class).error("Isochron Scepter: spell ability == null " + copiedCard.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
@ -91,7 +89,11 @@ 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());
|
||||||
|
if (permanent == null) {
|
||||||
|
permanent = game.getPermanent(source.getSourceId());
|
||||||
|
}
|
||||||
|
if (permanent != null) {
|
||||||
permanent.setName(card.getName());
|
permanent.setName(card.getName());
|
||||||
permanent.getColor(game).setColor(card.getColor(game));
|
permanent.getColor(game).setColor(card.getColor(game));
|
||||||
permanent.getManaCost().clear();
|
permanent.getManaCost().clear();
|
||||||
|
@ -113,9 +115,10 @@ public class QuicksilverGargantuan extends CardImpl {
|
||||||
for (Ability ability : card.getAbilities()) {
|
for (Ability ability : card.getAbilities()) {
|
||||||
permanent.addAbility(ability, game);
|
permanent.addAbility(ability, game);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QuicksilverGargantuanCopyEffect copy() {
|
public QuicksilverGargantuanCopyEffect copy() {
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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("}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue