Fixed NPE on game.getState() usage

This commit is contained in:
Oleg Agafonov 2020-08-26 13:34:08 +04:00
parent cf5b474c29
commit 8ce5c7f907
21 changed files with 97 additions and 83 deletions

View file

@ -4,9 +4,10 @@ import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.transfer.TransferManager; import com.amazonaws.services.s3.transfer.TransferManager;
import com.amazonaws.services.s3.transfer.Upload; import com.amazonaws.services.s3.transfer.Upload;
import java.io.File;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.io.File;
public class S3Uploader { public class S3Uploader {
private static final Logger logger = Logger.getLogger(S3Uploader.class); private static final Logger logger = Logger.getLogger(S3Uploader.class);
@ -18,9 +19,9 @@ public class S3Uploader {
String accessKeyId = System.getenv("AWS_ACCESS_ID"); String accessKeyId = System.getenv("AWS_ACCESS_ID");
String secretKeyId = System.getenv("AWS_SECRET_KEY"); String secretKeyId = System.getenv("AWS_SECRET_KEY");
if (accessKeyId == null || "".equals(accessKeyId) if (accessKeyId == null || accessKeyId.isEmpty()
|| secretKeyId == null || "".equals(secretKeyId) || secretKeyId == null || secretKeyId.isEmpty()
|| existingBucketName == null || "".equals(existingBucketName)) { || existingBucketName == null || existingBucketName.isEmpty()) {
logger.info("Aborting json log sync."); logger.info("Aborting json log sync.");
return false; return false;
} }

View file

@ -10,7 +10,10 @@ import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ChooseACardNameEffect; import mage.abilities.effects.common.ChooseACardNameEffect;
import mage.abilities.effects.common.DoWhenCostPaid; import mage.abilities.effects.common.DoWhenCostPaid;
import mage.abilities.keyword.MenaceAbility; import mage.abilities.keyword.MenaceAbility;
import mage.cards.*; import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubType; import mage.constants.SubType;
@ -79,10 +82,10 @@ class CabalTherapistDiscardEffect extends OneShotEffect {
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source)); Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId()); MageObject sourceObject = game.getObject(source.getSourceId());
if (targetPlayer == null || controller == null || sourceObject == null) { String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (targetPlayer == null || controller == null || sourceObject == null || cardName == null) {
return false; return false;
} }
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
Cards hand = targetPlayer.getHand().copy(); Cards hand = targetPlayer.getHand().copy();
targetPlayer.revealCards(source, hand, game); targetPlayer.revealCards(source, hand, game);
hand.removeIf(uuid -> { hand.removeIf(uuid -> {

View file

@ -6,10 +6,14 @@ import mage.abilities.costs.common.SacrificeTargetCost;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ChooseACardNameEffect; import mage.abilities.effects.common.ChooseACardNameEffect;
import mage.abilities.keyword.FlashbackAbility; import mage.abilities.keyword.FlashbackAbility;
import mage.cards.*; import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.TimingRule; import mage.constants.TimingRule;
import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetPlayer; import mage.target.TargetPlayer;
@ -17,7 +21,6 @@ import mage.target.common.TargetControlledCreaturePermanent;
import mage.util.CardUtil; import mage.util.CardUtil;
import java.util.UUID; import java.util.UUID;
import mage.filter.StaticFilters;
/** /**
* @author jonubuu * @author jonubuu
@ -64,10 +67,10 @@ class CabalTherapyEffect extends OneShotEffect {
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source)); Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId()); MageObject sourceObject = game.getObject(source.getSourceId());
if (targetPlayer == null || controller == null || sourceObject == null) { String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (targetPlayer == null || controller == null || sourceObject == null || cardName == null) {
return false; return false;
} }
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
Cards hand = targetPlayer.getHand().copy(); Cards hand = targetPlayer.getHand().copy();
targetPlayer.revealCards(source, hand, game); targetPlayer.revealCards(source, hand, game);
hand.removeIf(uuid -> { hand.removeIf(uuid -> {

View file

@ -1,7 +1,5 @@
package mage.cards.c; package mage.cards.c;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.AttacksTriggeredAbility; import mage.abilities.common.AttacksTriggeredAbility;
@ -10,18 +8,19 @@ import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ChooseACardNameEffect; import mage.abilities.effects.common.ChooseACardNameEffect;
import mage.abilities.effects.common.ChooseACardNameEffect.TypeOfName; import mage.abilities.effects.common.ChooseACardNameEffect.TypeOfName;
import mage.abilities.effects.common.cost.SpellsCostReductionAllEffect; import mage.abilities.effects.common.cost.SpellsCostReductionAllEffect;
import mage.constants.SubType;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubType;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate; import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import java.util.UUID;
/** /**
*
* @author TheElk801 * @author TheElk801
*/ */
public final class CheeringFanatic extends CardImpl { public final class CheeringFanatic extends CardImpl {
@ -67,6 +66,9 @@ class CheeringFanaticEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
new ChooseACardNameEffect(TypeOfName.ALL).apply(game, source); new ChooseACardNameEffect(TypeOfName.ALL).apply(game, source);
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (cardName == null) {
return false;
}
FilterCard filter = new FilterCard(); FilterCard filter = new FilterCard();
filter.add(new NamePredicate(cardName)); filter.add(new NamePredicate(cardName));
ContinuousEffect effect = new SpellsCostReductionAllEffect(filter, 1); ContinuousEffect effect = new SpellsCostReductionAllEffect(filter, 1);

View file

@ -74,7 +74,7 @@ enum ChromeReplicatorCondition implements Condition {
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(MageObject::getName) .map(MageObject::getName)
.filter(Objects::nonNull) .filter(Objects::nonNull)
.filter(s -> !"".equals(s)) .filter(s -> !s.isEmpty())
.anyMatch(s -> nameMap.compute(s, (x, i) -> i == null ? 1 : Integer.sum(i, 1)) >= 2); .anyMatch(s -> nameMap.compute(s, (x, i) -> i == null ? 1 : Integer.sum(i, 1)) >= 2);
} }
} }

View file

@ -93,7 +93,7 @@ class CouncilOfTheAbsoluteReplacementEffect extends ContinuousRuleModifyingEffec
if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
MageObject object = game.getObject(event.getSourceId()); MageObject object = game.getObject(event.getSourceId());
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
return object != null && CardUtil.haveSameNames(object, cardName, game); return object != null && cardName != null && CardUtil.haveSameNames(object, cardName, game);
} }
return false; return false;
} }

View file

@ -1,12 +1,11 @@
package mage.cards.d; package mage.cards.d;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.common.CounterTargetEffect;
import mage.abilities.effects.common.ChooseACardNameEffect; import mage.abilities.effects.common.ChooseACardNameEffect;
import mage.abilities.effects.common.CounterTargetEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
@ -17,8 +16,9 @@ import mage.game.Game;
import mage.target.TargetSpell; import mage.target.TargetSpell;
import mage.target.targetadjustment.TargetAdjuster; import mage.target.targetadjustment.TargetAdjuster;
import java.util.UUID;
/** /**
*
* @author jeffwadsworth * @author jeffwadsworth
*/ */
public final class DeclarationOfNaught extends CardImpl { public final class DeclarationOfNaught extends CardImpl {
@ -55,6 +55,9 @@ enum DeclarationOfNaughtAdjuster implements TargetAdjuster {
public void adjustTargets(Ability ability, Game game) { public void adjustTargets(Ability ability, Game game) {
ability.getTargets().clear(); ability.getTargets().clear();
String chosenName = (String) game.getState().getValue(ability.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); String chosenName = (String) game.getState().getValue(ability.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (chosenName == null) {
return;
}
FilterSpell filterSpell = new FilterSpell("spell named " + chosenName); FilterSpell filterSpell = new FilterSpell("spell named " + chosenName);
filterSpell.add(new NamePredicate(chosenName)); filterSpell.add(new NamePredicate(chosenName));
TargetSpell target = new TargetSpell(1, filterSpell); TargetSpell target = new TargetSpell(1, filterSpell);

View file

@ -79,7 +79,7 @@ class DementiaSliverEffect extends OneShotEffect {
Player opponent = game.getPlayer(targetPointer.getFirst(game, source)); Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
MageObject sourceObject = game.getObject(source.getSourceId()); MageObject sourceObject = game.getObject(source.getSourceId());
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (opponent != null && sourceObject != null && !cardName.isEmpty()) { if (opponent != null && sourceObject != null && cardName != null && !cardName.isEmpty()) {
if (!opponent.getHand().isEmpty()) { if (!opponent.getHand().isEmpty()) {
Cards revealed = new CardsImpl(); Cards revealed = new CardsImpl();
Card card = opponent.getHand().getRandom(game); Card card = opponent.getHand().getRandom(game);

View file

@ -1,7 +1,5 @@
package mage.cards.d; package mage.cards.d;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.common.ChooseACardNameEffect; import mage.abilities.effects.common.ChooseACardNameEffect;
import mage.abilities.effects.common.search.SearchTargetGraveyardHandLibraryForCardNameAndExileEffect; import mage.abilities.effects.common.search.SearchTargetGraveyardHandLibraryForCardNameAndExileEffect;
@ -11,8 +9,9 @@ import mage.constants.CardType;
import mage.game.Game; import mage.game.Game;
import mage.target.TargetPlayer; import mage.target.TargetPlayer;
import java.util.UUID;
/** /**
*
* @author fireshoes * @author fireshoes
*/ */
public final class Dispossess extends CardImpl { public final class Dispossess extends CardImpl {
@ -49,6 +48,9 @@ class DispossessEffect extends SearchTargetGraveyardHandLibraryForCardNameAndExi
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (cardName == null) {
return false;
}
return super.applySearchAndExile(game, source, cardName, targetPointer.getFirst(game, source)); return super.applySearchAndExile(game, source, cardName, targetPointer.getFirst(game, source));
} }

View file

@ -1,7 +1,5 @@
package mage.cards.f; package mage.cards.f;
import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
@ -19,6 +17,9 @@ import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType; import mage.game.events.GameEvent.EventType;
import mage.target.TargetSpell; import mage.target.TargetSpell;
import mage.util.CardUtil;
import java.util.UUID;
/** /**
* @author spjspj * @author spjspj
@ -72,9 +73,9 @@ class ComplyCantCastEffect extends ContinuousRuleModifyingEffectImpl {
@Override @Override
public String getInfoMessage(Ability source, GameEvent event, Game game) { public String getInfoMessage(Ability source, GameEvent event, Game game) {
MageObject mageObject = game.getObject(source.getSourceId()); MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject != null) {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
return "You may not cast a card named " + cardName + " (" + mageObject.getIdName() + ")."; if (mageObject != null && cardName != null) {
return "You can't cast a card named " + cardName + " (" + mageObject.getIdName() + ").";
} }
return null; return null;
} }
@ -89,9 +90,7 @@ class ComplyCantCastEffect extends ContinuousRuleModifyingEffectImpl {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) { if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
MageObject object = game.getObject(event.getSourceId()); MageObject object = game.getObject(event.getSourceId());
if (object != null && object.getName().equals(cardName)) { return object != null && CardUtil.haveSameNames(object, cardName, game);
return true;
}
} }
return false; return false;
} }

View file

@ -73,9 +73,9 @@ class GideonsInterventionCantCastEffect extends ContinuousRuleModifyingEffectImp
@Override @Override
public String getInfoMessage(Ability source, GameEvent event, Game game) { public String getInfoMessage(Ability source, GameEvent event, Game game) {
MageObject mageObject = game.getObject(source.getSourceId()); MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject != null) {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
return "You may not cast a card named " + cardName + " (" + mageObject.getIdName() + ")."; if (mageObject != null && cardName != null) {
return "You can't cast a card named " + cardName + " (" + mageObject.getIdName() + ").";
} }
return null; return null;
} }
@ -134,7 +134,6 @@ class GideonsInterventionPreventAllDamageEffect extends PreventionEffectImpl {
MageObject object = game.getObject(event.getSourceId()); MageObject object = game.getObject(event.getSourceId());
Permanent targetPerm = game.getPermanent(event.getTargetId()); Permanent targetPerm = game.getPermanent(event.getTargetId());
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (object != null && (event.getType() == GameEvent.EventType.DAMAGE_PLAYER if (object != null && (event.getType() == GameEvent.EventType.DAMAGE_PLAYER
|| targetPerm != null && (event.getType() == GameEvent.EventType.DAMAGE_CREATURE || targetPerm != null && (event.getType() == GameEvent.EventType.DAMAGE_CREATURE
|| event.getType() == GameEvent.EventType.DAMAGE_PLANESWALKER))) { || event.getType() == GameEvent.EventType.DAMAGE_PLANESWALKER))) {

View file

@ -1,8 +1,5 @@
package mage.cards.j; package mage.cards.j;
import java.util.Set;
import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility;
@ -14,16 +11,8 @@ import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.AsThoughEffectImpl; import mage.abilities.effects.AsThoughEffectImpl;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card; import mage.cards.*;
import mage.cards.CardImpl; import mage.constants.*;
import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.cards.SplitCard;
import mage.constants.AsThoughEffectType;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.game.ExileZone; import mage.game.ExileZone;
import mage.game.Game; import mage.game.Game;
@ -34,8 +23,10 @@ import mage.target.TargetSpell;
import mage.target.common.TargetCardInExile; import mage.target.common.TargetCardInExile;
import mage.util.CardUtil; import mage.util.CardUtil;
import java.util.Set;
import java.util.UUID;
/** /**
*
* @author jeffwadsworth * @author jeffwadsworth
*/ */
public final class JestersScepter extends CardImpl { public final class JestersScepter extends CardImpl {
@ -213,16 +204,13 @@ class JestersScepterCounterEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source)); Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
if (spell != null) { if (spell != null) {
// In case of Split Card
String nameOfExiledCardPayment = (String) game.getState().getValue(source.getSourceId() + "_nameOfExiledCardPayment"); String nameOfExiledCardPayment = (String) game.getState().getValue(source.getSourceId() + "_nameOfExiledCardPayment");
String nameOfExiledCardPayment2 = (String) game.getState().getValue(source.getSourceId() + "_nameOfExiledCardPayment2"); String nameOfExiledCardPayment2 = (String) game.getState().getValue(source.getSourceId() + "_nameOfExiledCardPayment2");
if (nameOfExiledCardPayment != null) { if (CardUtil.haveSameNames(spell.getCard(), nameOfExiledCardPayment, game)
if (nameOfExiledCardPayment.equals(spell.getCard().getName()) || CardUtil.haveSameNames(spell.getCard(), nameOfExiledCardPayment2, game)) {
|| (nameOfExiledCardPayment2 != null) && nameOfExiledCardPayment2.equals(spell.getCard().getName())) {
return game.getStack().counter(targetPointer.getFirst(game, source), source.getSourceId(), game); return game.getStack().counter(targetPointer.getFirst(game, source), source.getSourceId(), game);
} }
} }
}
return false; return false;
} }

View file

@ -78,7 +78,7 @@ class MedomaisProphecyTriggerEffect extends OneShotEffect {
String cardName = (String) game.getState().getValue( String cardName = (String) game.getState().getValue(
source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY
); );
if (cardName == null || "".equals(cardName)) { if (cardName == null || cardName.isEmpty()) {
return false; return false;
} }
game.addDelayedTriggeredAbility(new MedomaisProphecyDelayedTriggeredAbility(cardName), source); game.addDelayedTriggeredAbility(new MedomaisProphecyDelayedTriggeredAbility(cardName), source);

View file

@ -1,6 +1,5 @@
package mage.cards.m; package mage.cards.m;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.Mode; import mage.abilities.Mode;
import mage.abilities.effects.common.ChooseACardNameEffect; import mage.abilities.effects.common.ChooseACardNameEffect;
@ -11,8 +10,9 @@ import mage.constants.CardType;
import mage.game.Game; import mage.game.Game;
import mage.target.TargetPlayer; import mage.target.TargetPlayer;
import java.util.UUID;
/** /**
*
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public final class Memoricide extends CardImpl { public final class Memoricide extends CardImpl {
@ -51,6 +51,9 @@ class MemoricideEffect extends SearchTargetGraveyardHandLibraryForCardNameAndExi
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (cardName == null) {
return false;
}
return super.applySearchAndExile(game, source, cardName, targetPointer.getFirst(game, source)); return super.applySearchAndExile(game, source, cardName, targetPointer.getFirst(game, source));
} }

View file

@ -20,6 +20,7 @@ import mage.players.Player;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -79,7 +80,8 @@ class RegularExpression extends OneShotEffect {
source.getControllerId(), source.getSourceId(), game source.getControllerId(), source.getSourceId(), game
).stream() ).stream()
.map(Permanent::getName) .map(Permanent::getName)
.filter(s -> !"".equals(s)) .filter(Objects::nonNull)
.filter(s -> !s.isEmpty())
.map(NamePredicate::new) .map(NamePredicate::new)
.collect(Collectors.toList()); .collect(Collectors.toList());
FilterCard filter FilterCard filter

View file

@ -1,9 +1,5 @@
package mage.cards.s; package mage.cards.s;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -22,8 +18,11 @@ import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.util.CardUtil; import mage.util.CardUtil;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/** /**
*
* @author MarcoMarin / HCrescent * @author MarcoMarin / HCrescent
*/ */
public final class Shapeshifter extends CardImpl { public final class Shapeshifter extends CardImpl {
@ -116,8 +115,8 @@ class ShapeshifterContinuousEffect extends ContinuousEffectImpl {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
String lastChosen = (String) game.getState().getValue(source.getSourceId().toString() + "_Shapeshifter"); String lastChosen = (String) game.getState().getValue(source.getSourceId().toString() + "_Shapeshifter");
if (permanent != null && lastChosen != null) {
int lastChosenNumber = Integer.parseInt(lastChosen); int lastChosenNumber = Integer.parseInt(lastChosen);
permanent.getPower().modifyBaseValue(lastChosenNumber); permanent.getPower().modifyBaseValue(lastChosenNumber);
permanent.getToughness().modifyBaseValue(7 - lastChosenNumber); permanent.getToughness().modifyBaseValue(7 - lastChosenNumber);

View file

@ -1,7 +1,5 @@
package mage.cards.s; package mage.cards.s;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
@ -15,8 +13,9 @@ import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.target.common.TargetOpponent; import mage.target.common.TargetOpponent;
import java.util.UUID;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public final class SlaughterGames extends CardImpl { public final class SlaughterGames extends CardImpl {
@ -60,6 +59,9 @@ class SlaughterGamesEffect extends SearchTargetGraveyardHandLibraryForCardNameAn
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (cardName == null) {
return false;
}
return super.applySearchAndExile(game, source, cardName, targetPointer.getFirst(game, source)); return super.applySearchAndExile(game, source, cardName, targetPointer.getFirst(game, source));
} }

View file

@ -130,7 +130,7 @@ class StaffOfTheLetterMagusEffect extends OneShotEffect {
for (int i = 0; i < spellName.length(); i++) { for (int i = 0; i < spellName.length(); i++) {
char letter = spellName.charAt(i); char letter = spellName.charAt(i);
String chosenLetter = (String) game.getState().getValue(mageObject.getId() + "_letter"); String chosenLetter = (String) game.getState().getValue(mageObject.getId() + "_letter");
if (Character.isLetter(letter) && Character.toUpperCase(letter) == chosenLetter.charAt(0)) { if (chosenLetter != null && Character.isLetter(letter) && Character.toUpperCase(letter) == chosenLetter.charAt(0)) {
lifegainValue++; lifegainValue++;
} }
} }

View file

@ -1,7 +1,5 @@
package mage.cards.s; package mage.cards.s;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.common.ChooseACardNameEffect; import mage.abilities.effects.common.ChooseACardNameEffect;
import mage.abilities.effects.common.search.SearchTargetGraveyardHandLibraryForCardNameAndExileEffect; import mage.abilities.effects.common.search.SearchTargetGraveyardHandLibraryForCardNameAndExileEffect;
@ -12,8 +10,9 @@ import mage.constants.CardType;
import mage.game.Game; import mage.game.Game;
import mage.target.TargetPlayer; import mage.target.TargetPlayer;
import java.util.UUID;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public final class StainTheMind extends CardImpl { public final class StainTheMind extends CardImpl {
@ -52,6 +51,9 @@ class StainTheMindEffect extends SearchTargetGraveyardHandLibraryForCardNameAndE
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY); String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (cardName == null) {
return false;
}
return super.applySearchAndExile(game, source, cardName, targetPointer.getFirst(game, source)); return super.applySearchAndExile(game, source, cardName, targetPointer.getFirst(game, source));
} }

View file

@ -1,6 +1,6 @@
package mage.cards.t; package mage.cards.t;
import java.util.ArrayList; import mage.ApprovingObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.common.TapSourceCost;
@ -12,19 +12,21 @@ import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.common.FilterNonlandCard;
import mage.filter.predicate.Predicates; import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.stack.Spell; import mage.game.stack.Spell;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetCard;
import mage.watchers.common.SpellsCastWatcher; import mage.watchers.common.SpellsCastWatcher;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import mage.ApprovingObject;
import mage.filter.common.FilterNonlandCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.target.TargetCard;
/** /**
* @author jeffwadsworth * @author jeffwadsworth
@ -95,7 +97,8 @@ class TwinningGlassEffect extends OneShotEffect {
} }
List<NamePredicate> predicates = spells.stream() List<NamePredicate> predicates = spells.stream()
.map(Spell::getName) .map(Spell::getName)
.filter(s -> !"".equals(s)) .filter(Objects::nonNull)
.filter(s -> !s.isEmpty())
.map(NamePredicate::new) .map(NamePredicate::new)
.collect(Collectors.toList()); .collect(Collectors.toList());
FilterNonlandCard filterCard = new FilterNonlandCard("nonland card that was cast this turn"); FilterNonlandCard filterCard = new FilterNonlandCard("nonland card that was cast this turn");

View file

@ -27,6 +27,9 @@ public class NamePredicate implements Predicate<MageObject> {
@Override @Override
public boolean apply(MageObject input, Game game) { public boolean apply(MageObject input, Game game) {
if (name == null) {
return false;
}
// If a player names a card, the player may name either half of a split card, but not both. // If a player names a card, the player may name either half of a split card, but not both.
// A split card has the chosen name if one of its two names matches the chosen name. // A split card has the chosen name if one of its two names matches the chosen name.
if (input instanceof SplitCard) { if (input instanceof SplitCard) {