From be6a588a7fab53ecf374abc54c1fc88b02a8e302 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sun, 15 Dec 2019 15:00:31 +0400 Subject: [PATCH] Fixed NPE errors --- Mage.Sets/src/mage/cards/b/BolassCitadel.java | 4 ++-- Mage.Sets/src/mage/cards/c/CovetousUrge.java | 3 ++- Mage.Sets/src/mage/cards/c/CunningAbduction.java | 2 +- Mage.Sets/src/mage/cards/d/DaxosOfMeletis.java | 2 +- Mage.Sets/src/mage/cards/d/DeadMansChest.java | 3 ++- Mage.Sets/src/mage/cards/d/DireFleetDaredevil.java | 3 ++- Mage.Sets/src/mage/cards/g/GrenzoHavocRaiser.java | 2 +- Mage.Sets/src/mage/cards/h/HostageTaker.java | 2 +- Mage.Sets/src/mage/cards/m/MnemonicBetrayal.java | 8 +++++--- Mage.Sets/src/mage/cards/o/OathOfNissa.java | 3 ++- Mage.Sets/src/mage/cards/p/PsychicIntrusion.java | 4 ++-- Mage.Sets/src/mage/cards/q/QuicksilverElemental.java | 3 ++- Mage.Sets/src/mage/cards/r/RobberOfTheRich.java | 2 +- Mage.Sets/src/mage/cards/s/StolenStrategy.java | 2 +- Mage.Sets/src/mage/cards/t/ThiefOfSanity.java | 2 +- Mage.Sets/src/mage/cards/t/TobiasBeckett.java | 2 +- Mage.Sets/src/mage/cards/v/VizierOfTheMenagerie.java | 3 ++- .../effects/common/continuous/PlayTheTopCardEffect.java | 3 ++- Mage/src/main/java/mage/util/CardUtil.java | 7 ++++++- 19 files changed, 37 insertions(+), 23 deletions(-) diff --git a/Mage.Sets/src/mage/cards/b/BolassCitadel.java b/Mage.Sets/src/mage/cards/b/BolassCitadel.java index 5741a658b0..a571e2fd26 100644 --- a/Mage.Sets/src/mage/cards/b/BolassCitadel.java +++ b/Mage.Sets/src/mage/cards/b/BolassCitadel.java @@ -22,9 +22,9 @@ import mage.filter.predicate.mageobject.CardTypePredicate; import mage.game.Game; import mage.players.Player; import mage.target.common.TargetControlledPermanent; +import mage.util.CardUtil; import java.util.UUID; -import mage.abilities.costs.Cost; /** * @author jeffwadsworth @@ -97,7 +97,7 @@ class BolassCitadelPlayTheTopCardEffect extends AsThoughEffectImpl { @Override public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) { Card cardToCheck = game.getCard(objectId); - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards if (playerId.equals(source.getControllerId()) && cardToCheck.isOwnedBy(source.getControllerId())) { Player controller = game.getPlayer(cardToCheck.getOwnerId()); diff --git a/Mage.Sets/src/mage/cards/c/CovetousUrge.java b/Mage.Sets/src/mage/cards/c/CovetousUrge.java index b3cf2030bf..051a0973d5 100644 --- a/Mage.Sets/src/mage/cards/c/CovetousUrge.java +++ b/Mage.Sets/src/mage/cards/c/CovetousUrge.java @@ -18,6 +18,7 @@ import mage.target.common.TargetCardInGraveyard; import mage.target.common.TargetCardInHand; import mage.target.common.TargetOpponent; import mage.target.targetpointer.FixedTarget; +import mage.util.CardUtil; import java.util.Objects; import java.util.UUID; @@ -156,7 +157,7 @@ class CovetousUrgeSpendAnyManaEffect extends AsThoughEffectImpl implements AsTho @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); return source.isControlledBy(affectedControllerId) && Objects.equals(objectId, fixedTarget.getTarget()) diff --git a/Mage.Sets/src/mage/cards/c/CunningAbduction.java b/Mage.Sets/src/mage/cards/c/CunningAbduction.java index d0d5bd1cc4..e070eaf1aa 100644 --- a/Mage.Sets/src/mage/cards/c/CunningAbduction.java +++ b/Mage.Sets/src/mage/cards/c/CunningAbduction.java @@ -122,7 +122,7 @@ class CunningAbductionSpendAnyManaEffect extends AsThoughEffectImpl implements A @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget()) && game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) { // if the card moved from exile to spell the zone change counter is increased by 1 (effect must applies before and on stack, use isCheckPlayableMode?) diff --git a/Mage.Sets/src/mage/cards/d/DaxosOfMeletis.java b/Mage.Sets/src/mage/cards/d/DaxosOfMeletis.java index da160f068f..2611031369 100644 --- a/Mage.Sets/src/mage/cards/d/DaxosOfMeletis.java +++ b/Mage.Sets/src/mage/cards/d/DaxosOfMeletis.java @@ -177,7 +177,7 @@ class DaxosOfMeletisSpendAnyManaEffect extends AsThoughEffectImpl implements AsT @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); return source.isControlledBy(affectedControllerId) && Objects.equals(objectId, fixedTarget.getTarget()) diff --git a/Mage.Sets/src/mage/cards/d/DeadMansChest.java b/Mage.Sets/src/mage/cards/d/DeadMansChest.java index c88eabc0f7..1a20378b82 100644 --- a/Mage.Sets/src/mage/cards/d/DeadMansChest.java +++ b/Mage.Sets/src/mage/cards/d/DeadMansChest.java @@ -22,6 +22,7 @@ import mage.players.ManaPoolItem; import mage.players.Player; import mage.target.TargetPermanent; import mage.target.targetpointer.FixedTarget; +import mage.util.CardUtil; import java.util.Set; import java.util.UUID; @@ -169,7 +170,7 @@ class DeadMansChestSpendManaEffect extends AsThoughEffectImpl implements AsThoug @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget()) && game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) { // if the card moved from exile to spell the zone change counter is increased by 1 (effect must applies before and on stack, use isCheckPlayableMode?) diff --git a/Mage.Sets/src/mage/cards/d/DireFleetDaredevil.java b/Mage.Sets/src/mage/cards/d/DireFleetDaredevil.java index bf72d24447..0b068cb21a 100644 --- a/Mage.Sets/src/mage/cards/d/DireFleetDaredevil.java +++ b/Mage.Sets/src/mage/cards/d/DireFleetDaredevil.java @@ -21,6 +21,7 @@ import mage.players.ManaPoolItem; import mage.players.Player; import mage.target.common.TargetCardInOpponentsGraveyard; import mage.target.targetpointer.FixedTarget; +import mage.util.CardUtil; import java.util.Objects; import java.util.UUID; @@ -133,7 +134,7 @@ class DireFleetDaredevilSpendAnyManaEffect extends AsThoughEffectImpl implements @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); return source.isControlledBy(affectedControllerId) && Objects.equals(objectId, ((FixedTarget) getTargetPointer()).getTarget()) diff --git a/Mage.Sets/src/mage/cards/g/GrenzoHavocRaiser.java b/Mage.Sets/src/mage/cards/g/GrenzoHavocRaiser.java index 6553e92444..dc1fbbc254 100644 --- a/Mage.Sets/src/mage/cards/g/GrenzoHavocRaiser.java +++ b/Mage.Sets/src/mage/cards/g/GrenzoHavocRaiser.java @@ -233,7 +233,7 @@ class GrenzoHavocRaiserSpendAnyManaEffect extends AsThoughEffectImpl implements @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); return source.isControlledBy(affectedControllerId) && Objects.equals(objectId, ((FixedTarget) getTargetPointer()).getTarget()) diff --git a/Mage.Sets/src/mage/cards/h/HostageTaker.java b/Mage.Sets/src/mage/cards/h/HostageTaker.java index 64ff610c52..3ef3f60d88 100644 --- a/Mage.Sets/src/mage/cards/h/HostageTaker.java +++ b/Mage.Sets/src/mage/cards/h/HostageTaker.java @@ -173,7 +173,7 @@ class HostageTakerSpendAnyManaEffect extends AsThoughEffectImpl implements AsTho @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); return source.isControlledBy(affectedControllerId) && Objects.equals(objectId, fixedTarget.getTarget()) diff --git a/Mage.Sets/src/mage/cards/m/MnemonicBetrayal.java b/Mage.Sets/src/mage/cards/m/MnemonicBetrayal.java index 757e38dd83..07101bdc0d 100644 --- a/Mage.Sets/src/mage/cards/m/MnemonicBetrayal.java +++ b/Mage.Sets/src/mage/cards/m/MnemonicBetrayal.java @@ -3,18 +3,20 @@ package mage.cards.m; import mage.abilities.Ability; import mage.abilities.DelayedTriggeredAbility; import mage.abilities.effects.AsThoughEffectImpl; +import mage.abilities.effects.AsThoughManaEffect; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.ExileSpellEffect; import mage.cards.*; import mage.constants.*; import mage.game.Game; import mage.game.events.GameEvent; +import mage.players.ManaPoolItem; import mage.players.Player; +import mage.util.CardUtil; + import java.util.HashMap; import java.util.Map; import java.util.UUID; -import mage.abilities.effects.AsThoughManaEffect; -import mage.players.ManaPoolItem; /** * @author TheElk801 @@ -156,7 +158,7 @@ class MnemonicBetrayalAnyColorEffect extends AsThoughEffectImpl implements AsTho @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards if (objectId.equals(card.getId()) && card.getZoneChangeCounter(game) <= zoneCounter + 1 && affectedControllerId.equals(source.getControllerId())) { diff --git a/Mage.Sets/src/mage/cards/o/OathOfNissa.java b/Mage.Sets/src/mage/cards/o/OathOfNissa.java index 04821b21b9..34f1e1b060 100644 --- a/Mage.Sets/src/mage/cards/o/OathOfNissa.java +++ b/Mage.Sets/src/mage/cards/o/OathOfNissa.java @@ -16,6 +16,7 @@ import mage.game.Game; import mage.players.ManaPoolItem; import mage.players.Player; import mage.target.TargetCard; +import mage.util.CardUtil; import java.util.UUID; @@ -127,7 +128,7 @@ class OathOfNissaSpendAnyManaEffect extends AsThoughEffectImpl implements AsThou @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards if (source.isControlledBy(affectedControllerId)) { MageObject mageObject = game.getObject(objectId); return mageObject != null && mageObject.isPlaneswalker(); diff --git a/Mage.Sets/src/mage/cards/p/PsychicIntrusion.java b/Mage.Sets/src/mage/cards/p/PsychicIntrusion.java index 9383eae170..40c1684df6 100644 --- a/Mage.Sets/src/mage/cards/p/PsychicIntrusion.java +++ b/Mage.Sets/src/mage/cards/p/PsychicIntrusion.java @@ -144,7 +144,7 @@ class PsychicIntrusionCastFromExileEffect extends AsThoughEffectImpl { @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards if (objectId.equals(getTargetPointer().getFirst(game, source))) { return affectedControllerId.equals(source.getControllerId()); } else { @@ -180,7 +180,7 @@ class PsychicIntrusionSpendAnyManaEffect extends AsThoughEffectImpl implements A @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget()) && game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) { // if the card moved from exile to spell the zone change counter is increased by 1 (effect must applies before and on stack, use isCheckPlayableMode?) diff --git a/Mage.Sets/src/mage/cards/q/QuicksilverElemental.java b/Mage.Sets/src/mage/cards/q/QuicksilverElemental.java index 24734a42a8..2a68085555 100644 --- a/Mage.Sets/src/mage/cards/q/QuicksilverElemental.java +++ b/Mage.Sets/src/mage/cards/q/QuicksilverElemental.java @@ -18,6 +18,7 @@ import mage.game.permanent.Permanent; import mage.players.ManaPoolItem; import mage.target.common.TargetCreaturePermanent; import mage.target.targetpointer.FixedTarget; +import mage.util.CardUtil; import java.util.UUID; @@ -141,7 +142,7 @@ class QuickSilverElementalBlueManaEffect extends AsThoughEffectImpl implements A @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards if (objectId.equals(getTargetPointer().getFirst(game, source))) { return affectedControllerId.equals(source.getControllerId()); } diff --git a/Mage.Sets/src/mage/cards/r/RobberOfTheRich.java b/Mage.Sets/src/mage/cards/r/RobberOfTheRich.java index 68c79579ec..f86c8b999a 100644 --- a/Mage.Sets/src/mage/cards/r/RobberOfTheRich.java +++ b/Mage.Sets/src/mage/cards/r/RobberOfTheRich.java @@ -194,7 +194,7 @@ class RobberOfTheRichSpendAnyManaEffect extends AsThoughEffectImpl implements As @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); return source.isControlledBy(affectedControllerId) && Objects.equals(objectId, fixedTarget.getTarget()) diff --git a/Mage.Sets/src/mage/cards/s/StolenStrategy.java b/Mage.Sets/src/mage/cards/s/StolenStrategy.java index 9a89e8c370..d9b04a41c1 100644 --- a/Mage.Sets/src/mage/cards/s/StolenStrategy.java +++ b/Mage.Sets/src/mage/cards/s/StolenStrategy.java @@ -157,7 +157,7 @@ class StolenStrategySpendAnyManaEffect extends AsThoughEffectImpl implements AsT @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); return source.isControlledBy(affectedControllerId) && Objects.equals(objectId, fixedTarget.getTarget()) diff --git a/Mage.Sets/src/mage/cards/t/ThiefOfSanity.java b/Mage.Sets/src/mage/cards/t/ThiefOfSanity.java index 2a44855fa2..64c5954eeb 100644 --- a/Mage.Sets/src/mage/cards/t/ThiefOfSanity.java +++ b/Mage.Sets/src/mage/cards/t/ThiefOfSanity.java @@ -187,7 +187,7 @@ class ThiefOfSanitySpendAnyManaEffect extends AsThoughEffectImpl implements AsTh @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards if (objectId.equals(((FixedTarget) getTargetPointer()).getTarget()) && game.getState().getZoneChangeCounter(objectId) <= ((FixedTarget) getTargetPointer()).getZoneChangeCounter() + 1) { // if the card moved from exile to spell the zone change counter is increased by 1 (effect must applies before and on stack, use isCheckPlayableMode?) diff --git a/Mage.Sets/src/mage/cards/t/TobiasBeckett.java b/Mage.Sets/src/mage/cards/t/TobiasBeckett.java index 0ad1a9c4ae..749b1eaa4d 100644 --- a/Mage.Sets/src/mage/cards/t/TobiasBeckett.java +++ b/Mage.Sets/src/mage/cards/t/TobiasBeckett.java @@ -172,7 +172,7 @@ class TobiasBeckettSpendAnyManaEffect extends AsThoughEffectImpl implements AsTh @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards FixedTarget fixedTarget = ((FixedTarget) getTargetPointer()); return source.isControlledBy(affectedControllerId) && Objects.equals(objectId, fixedTarget.getTarget()) diff --git a/Mage.Sets/src/mage/cards/v/VizierOfTheMenagerie.java b/Mage.Sets/src/mage/cards/v/VizierOfTheMenagerie.java index 6e424515cf..8583afb86c 100644 --- a/Mage.Sets/src/mage/cards/v/VizierOfTheMenagerie.java +++ b/Mage.Sets/src/mage/cards/v/VizierOfTheMenagerie.java @@ -14,6 +14,7 @@ import mage.constants.*; import mage.game.Game; import mage.players.ManaPoolItem; import mage.players.Player; +import mage.util.CardUtil; import java.util.UUID; @@ -117,7 +118,7 @@ class VizierOfTheMenagerieManaEffect extends AsThoughEffectImpl implements AsTho @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards if (source.isControlledBy(affectedControllerId)) { MageObject mageObject = game.getObject(objectId); return mageObject != null && mageObject.isCreature(); diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/PlayTheTopCardEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/PlayTheTopCardEffect.java index 63078c0d75..2d369f0f4d 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/PlayTheTopCardEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/PlayTheTopCardEffect.java @@ -9,6 +9,7 @@ import mage.constants.Outcome; import mage.filter.FilterCard; import mage.game.Game; import mage.players.Player; +import mage.util.CardUtil; import java.util.UUID; @@ -53,7 +54,7 @@ public class PlayTheTopCardEffect extends AsThoughEffectImpl { @Override public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) { Card cardToCheck = game.getCard(objectId); - objectId = game.getCard(objectId).getMainCard().getId(); // for split cards + objectId = CardUtil.getMainCardId(game, objectId); // for split cards if (cardToCheck != null && playerId.equals(source.getControllerId()) diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 85770a50a3..65a8cd646e 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -565,7 +565,7 @@ public final class CardUtil { public static boolean haveSameNames(String name1, String name2, Boolean ignoreMtgRuleForEmptyNames) { if (ignoreMtgRuleForEmptyNames) { // simple compare for tests and engine - return name1 != null && name2 != null && name1.equals(name2); + return name1 != null && name1.equals(name2); } else { // mtg logic compare for game (empty names can't be same) return !haveEmptyName(name1) && !haveEmptyName(name2) && name1.equals(name2); @@ -587,4 +587,9 @@ public final class CardUtil { public static boolean haveEmptyName(MageObject object) { return object == null || haveEmptyName(object.getName()); } + + public static UUID getMainCardId(Game game, UUID objectId) { + Card card = game.getCard(objectId); + return card != null ? card.getMainCard().getId() : objectId; + } }