From 745bfa2836a927a0c52d989642677bbd1ccf9583 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Wed, 15 Jan 2020 07:08:56 +0400 Subject: [PATCH] Fixed NPE errors on missing card (game.getCard can't find card); --- Mage.Sets/src/mage/cards/d/DanceOfTheManse.java | 1 + Mage.Sets/src/mage/cards/d/DeathbellowWarCry.java | 2 ++ Mage.Sets/src/mage/cards/d/DiscordantDirge.java | 12 ++++++------ Mage.Sets/src/mage/cards/f/ForeverYoung.java | 2 ++ Mage.Sets/src/mage/cards/k/KethisTheHiddenHand.java | 2 ++ Mage.Sets/src/mage/cards/s/ScrollOfFate.java | 13 ++++++++----- Mage.Sets/src/mage/cards/s/SharedSummons.java | 2 ++ Mage/src/main/java/mage/cards/CardsImpl.java | 2 +- Mage/src/main/java/mage/players/Library.java | 2 +- 9 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Mage.Sets/src/mage/cards/d/DanceOfTheManse.java b/Mage.Sets/src/mage/cards/d/DanceOfTheManse.java index 195f129459..75dcf91da6 100644 --- a/Mage.Sets/src/mage/cards/d/DanceOfTheManse.java +++ b/Mage.Sets/src/mage/cards/d/DanceOfTheManse.java @@ -99,6 +99,7 @@ class DanceOfTheManseEffect extends OneShotEffect { .map(Target::getTargets) .flatMap(Collection::stream) .map(game::getCard) + .filter(Objects::nonNull) .collect(Collectors.toSet())); player.moveCards(cards, Zone.BATTLEFIELD, source, game); if (source.getManaCostsToPay().getX() < 6) { diff --git a/Mage.Sets/src/mage/cards/d/DeathbellowWarCry.java b/Mage.Sets/src/mage/cards/d/DeathbellowWarCry.java index 911186f034..3a4c639968 100644 --- a/Mage.Sets/src/mage/cards/d/DeathbellowWarCry.java +++ b/Mage.Sets/src/mage/cards/d/DeathbellowWarCry.java @@ -13,6 +13,7 @@ import mage.filter.common.FilterCreatureCard; import mage.game.Game; import mage.target.common.TargetCardInLibrary; +import java.util.Objects; import java.util.UUID; /** @@ -68,6 +69,7 @@ class DeathbellowWarCryTarget extends TargetCardInLibrary { .getTargets() .stream() .map(game::getCard) + .filter(Objects::nonNull) .map(Card::getName) .noneMatch(card.getName()::equals); } diff --git a/Mage.Sets/src/mage/cards/d/DiscordantDirge.java b/Mage.Sets/src/mage/cards/d/DiscordantDirge.java index dcac03578f..4d2c5f9405 100644 --- a/Mage.Sets/src/mage/cards/d/DiscordantDirge.java +++ b/Mage.Sets/src/mage/cards/d/DiscordantDirge.java @@ -1,6 +1,5 @@ package mage.cards.d; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; @@ -8,7 +7,6 @@ import mage.abilities.costs.common.SacrificeSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; -import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; @@ -23,8 +21,10 @@ import mage.players.Player; import mage.target.TargetCard; import mage.target.common.TargetOpponent; +import java.util.Objects; +import java.util.UUID; + /** - * * @author jeffwadsworth */ public final class DiscordantDirge extends CardImpl { @@ -81,9 +81,9 @@ class DiscordantDirgeEffect extends OneShotEffect { TargetCard target = new TargetCard(0, verseCounters, Zone.HAND, new FilterCard()); target.setNotTarget(true); if (controller.choose(Outcome.Benefit, targetOpponent.getHand(), target, game)) { - target.getTargets().stream().map(game::getCard).filter((card) -> (card != null - && targetOpponent.getHand().contains(card.getId()))).forEachOrdered((card) -> { - targetOpponent.discard(card, source, game); + target.getTargets().stream().map(game::getCard).filter(Objects::nonNull).filter((card) -> (card != null + && targetOpponent.getHand().contains(card.getId()))).forEachOrdered((card) -> { + targetOpponent.discard(card, source, game); }); return true; } diff --git a/Mage.Sets/src/mage/cards/f/ForeverYoung.java b/Mage.Sets/src/mage/cards/f/ForeverYoung.java index abfe7a967f..3ffce98390 100644 --- a/Mage.Sets/src/mage/cards/f/ForeverYoung.java +++ b/Mage.Sets/src/mage/cards/f/ForeverYoung.java @@ -15,6 +15,7 @@ import mage.target.Target; import mage.target.common.TargetCardInYourGraveyard; import java.util.Collection; +import java.util.Objects; import java.util.UUID; import java.util.stream.Collectors; @@ -74,6 +75,7 @@ class ForeverYoungEffect extends OneShotEffect { .map(Target::getTargets) .flatMap(Collection::stream) .map(game::getCard) + .filter(Objects::nonNull) .collect(Collectors.toSet()) ), game, source, true); } diff --git a/Mage.Sets/src/mage/cards/k/KethisTheHiddenHand.java b/Mage.Sets/src/mage/cards/k/KethisTheHiddenHand.java index ebb328aaa9..2198706b4d 100644 --- a/Mage.Sets/src/mage/cards/k/KethisTheHiddenHand.java +++ b/Mage.Sets/src/mage/cards/k/KethisTheHiddenHand.java @@ -18,6 +18,7 @@ import mage.game.Game; import mage.players.Player; import mage.target.common.TargetCardInYourGraveyard; +import java.util.Objects; import java.util.UUID; /** @@ -88,6 +89,7 @@ class KethisTheHiddenHandEffect extends ContinuousEffectImpl { player.getGraveyard() .stream() .map(game::getCard) + .filter(Objects::nonNull) .filter(Card::isLegendary) .forEach(card -> affectedObjectList.add(new MageObjectReference(card, game))); } diff --git a/Mage.Sets/src/mage/cards/s/ScrollOfFate.java b/Mage.Sets/src/mage/cards/s/ScrollOfFate.java index a536ba7b24..882eff8bab 100644 --- a/Mage.Sets/src/mage/cards/s/ScrollOfFate.java +++ b/Mage.Sets/src/mage/cards/s/ScrollOfFate.java @@ -17,10 +17,12 @@ import mage.constants.Outcome; import mage.constants.Zone; import mage.game.Game; import mage.players.Player; +import mage.target.common.TargetCardInHand; + +import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; -import mage.target.common.TargetCardInHand; /** * @author TheElk801 @@ -31,7 +33,7 @@ public final class ScrollOfFate extends CardImpl { super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{3}"); // {T}: Manifest a card from your hand. - this.addAbility(new SimpleActivatedAbility(new ScrollOfFateEffect(), + this.addAbility(new SimpleActivatedAbility(new ScrollOfFateEffect(), new TapSourceCost())); } @@ -69,7 +71,7 @@ class ScrollOfFateEffect extends OneShotEffect { return false; } TargetCardInHand targetCard = new TargetCardInHand(); - if (!controller.chooseTarget(Outcome.PutCardInPlay, controller.getHand(), + if (!controller.chooseTarget(Outcome.PutCardInPlay, controller.getHand(), targetCard, source, game)) { return false; } @@ -79,6 +81,7 @@ class ScrollOfFateEffect extends OneShotEffect { .getTargets() .stream() .map(game::getCard) + .filter(Objects::nonNull) .collect(Collectors.toSet()); cards.stream().forEach(card -> { ManaCosts manaCosts = null; @@ -88,9 +91,9 @@ class ScrollOfFateEffect extends OneShotEffect { manaCosts = new ManaCostsImpl("{0}"); } } - MageObjectReference objectReference = new MageObjectReference(card.getId(), + MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game); - game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, + game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, BecomesFaceDownCreatureEffect.FaceDownType.MANIFESTED), newSource); }); controller.moveCards(cards, Zone.BATTLEFIELD, source, game, false, true, false, null); diff --git a/Mage.Sets/src/mage/cards/s/SharedSummons.java b/Mage.Sets/src/mage/cards/s/SharedSummons.java index f49b10117c..e8c306985e 100644 --- a/Mage.Sets/src/mage/cards/s/SharedSummons.java +++ b/Mage.Sets/src/mage/cards/s/SharedSummons.java @@ -12,6 +12,7 @@ import mage.filter.common.FilterCreatureCard; import mage.game.Game; import mage.target.common.TargetCardInLibrary; +import java.util.Objects; import java.util.UUID; /** @@ -70,6 +71,7 @@ class SharedSummonsTarget extends TargetCardInLibrary { .getTargets() .stream() .map(game::getCard) + .filter(Objects::nonNull) .noneMatch(c -> c != null && c.getName().equals(card.getName())); } } diff --git a/Mage/src/main/java/mage/cards/CardsImpl.java b/Mage/src/main/java/mage/cards/CardsImpl.java index 7f3ba80197..250bb3f3b8 100644 --- a/Mage/src/main/java/mage/cards/CardsImpl.java +++ b/Mage/src/main/java/mage/cards/CardsImpl.java @@ -129,7 +129,7 @@ public class CardsImpl extends LinkedHashSet implements Cards, Serializabl @Override public Set getCards(FilterCard filter, Game game) { - return stream().map(game::getCard).filter(card -> filter.match(card, game)).collect(Collectors.toSet()); + return stream().map(game::getCard).filter(Objects::nonNull).filter(card -> filter.match(card, game)).collect(Collectors.toSet()); } @Override diff --git a/Mage/src/main/java/mage/players/Library.java b/Mage/src/main/java/mage/players/Library.java index 3f930f781f..82323073e8 100644 --- a/Mage/src/main/java/mage/players/Library.java +++ b/Mage/src/main/java/mage/players/Library.java @@ -164,7 +164,7 @@ public class Library implements Serializable { * @return */ public List getCards(Game game) { - return library.stream().map(game::getCard).collect(Collectors.toList()); + return library.stream().map(game::getCard).filter(Objects::nonNull).collect(Collectors.toList()); } public Set getTopCards(Game game, int amount) {