From 454d76e30b4e408707ae7bd4d7ebedb1f1e4e881 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Fri, 8 Feb 2019 17:30:47 +0400 Subject: [PATCH] Fixed NPE errors in canAttack restrict checks; --- Mage.Sets/src/mage/cards/a/Arboria.java | 9 +++-- .../src/mage/cards/c/CrownHunterHireling.java | 10 +++--- Mage.Sets/src/mage/cards/g/GoblinGoon.java | 24 ++++++------- .../src/mage/cards/i/IllusionistsGambit.java | 35 +++++++------------ Mage.Sets/src/mage/cards/m/MoggToady.java | 24 ++++++------- .../src/mage/cards/m/MonstrousHound.java | 10 ++++-- Mage.Sets/src/mage/cards/t/TeferisMoat.java | 22 ++++++------ Mage.Sets/src/mage/cards/w/WebOfInertia.java | 14 ++++---- .../src/mage/cards/x/XantchaSleeperAgent.java | 4 +++ .../abilities/effects/RestrictionEffect.java | 12 +++++-- .../CantAttackControllerAttachedEffect.java | 10 +++--- ...CantAttackIfDefenderControlsPermanent.java | 10 +++--- ...ttackUnlessDefenderControllsPermanent.java | 15 ++++---- .../common/combat/CantAttackYouAllEffect.java | 5 +-- .../common/combat/CantAttackYouEffect.java | 8 +++-- .../CantAttackYouOrPlaneswalkerAllEffect.java | 9 +++-- .../mage/game/command/planes/AgyremPlane.java | 13 ++++--- 17 files changed, 128 insertions(+), 106 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/Arboria.java b/Mage.Sets/src/mage/cards/a/Arboria.java index 6fa2572c54a..11b2d7ba0af 100644 --- a/Mage.Sets/src/mage/cards/a/Arboria.java +++ b/Mage.Sets/src/mage/cards/a/Arboria.java @@ -1,7 +1,5 @@ - package mage.cards.a; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.RestrictionEffect; @@ -17,8 +15,9 @@ import mage.game.permanent.PermanentToken; import mage.watchers.common.CastSpellYourLastTurnWatcher; import mage.watchers.common.PermanentsEnteredBattlefieldYourLastTurnWatcher; +import java.util.UUID; + /** - * * @author spjspj */ public final class Arboria extends CardImpl { @@ -60,6 +59,10 @@ class ArboriaEffect extends RestrictionEffect { @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } + CastSpellYourLastTurnWatcher watcher = game.getState().getWatcher(CastSpellYourLastTurnWatcher.class); if (watcher != null && watcher.getAmountOfSpellsCastOnPlayersTurn(defenderId) > 0) { return true; diff --git a/Mage.Sets/src/mage/cards/c/CrownHunterHireling.java b/Mage.Sets/src/mage/cards/c/CrownHunterHireling.java index 59dbb7d4324..c2f31d056b7 100644 --- a/Mage.Sets/src/mage/cards/c/CrownHunterHireling.java +++ b/Mage.Sets/src/mage/cards/c/CrownHunterHireling.java @@ -1,7 +1,5 @@ - package mage.cards.c; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; @@ -11,14 +9,15 @@ import mage.abilities.effects.common.BecomesMonarchSourceEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.SubType; import mage.constants.Duration; +import mage.constants.SubType; import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; +import java.util.UUID; + /** - * * @author LevelX2 */ public final class CrownHunterHireling extends CardImpl { @@ -66,6 +65,9 @@ class CrownHunterHirelingCantAttackEffect extends RestrictionEffect { @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } return defenderId.equals(game.getMonarchId()); } diff --git a/Mage.Sets/src/mage/cards/g/GoblinGoon.java b/Mage.Sets/src/mage/cards/g/GoblinGoon.java index eff8408b09d..b448b4f7036 100644 --- a/Mage.Sets/src/mage/cards/g/GoblinGoon.java +++ b/Mage.Sets/src/mage/cards/g/GoblinGoon.java @@ -1,7 +1,5 @@ - package mage.cards.g; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; @@ -9,22 +7,23 @@ import mage.abilities.effects.RestrictionEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.SubType; import mage.constants.Duration; +import mage.constants.SubType; import mage.constants.Zone; import mage.filter.common.FilterControlledCreaturePermanent; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; +import java.util.UUID; + /** - * * @author emerald000 */ public final class GoblinGoon extends CardImpl { public GoblinGoon(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{R}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{R}"); this.subtype.add(SubType.GOBLIN); this.subtype.add(SubType.MUTANT); this.power = new MageInt(6); @@ -32,7 +31,7 @@ public final class GoblinGoon extends CardImpl { // Goblin Goon can't attack unless you control more creatures than defending player. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GoblinGoonCantAttackEffect())); - + // Goblin Goon can't block unless you control more creatures than attacking player. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GoblinGoonCantBlockEffect())); } @@ -65,24 +64,25 @@ class GoblinGoonCantAttackEffect extends RestrictionEffect { @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } + UUID defendingPlayerId; Player defender = game.getPlayer(defenderId); if (defender == null) { Permanent permanent = game.getPermanent(defenderId); if (permanent != null) { defendingPlayerId = permanent.getControllerId(); - } - else { + } else { return false; } - } - else { + } else { defendingPlayerId = defenderId; } if (defendingPlayerId != null) { return game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), source.getControllerId(), game) > game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), defendingPlayerId, game); - } - else { + } else { return true; } } diff --git a/Mage.Sets/src/mage/cards/i/IllusionistsGambit.java b/Mage.Sets/src/mage/cards/i/IllusionistsGambit.java index b624891e7a2..39f31ee20e7 100644 --- a/Mage.Sets/src/mage/cards/i/IllusionistsGambit.java +++ b/Mage.Sets/src/mage/cards/i/IllusionistsGambit.java @@ -1,9 +1,5 @@ - package mage.cards.i; -import java.util.List; -import java.util.Objects; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.CastOnlyDuringPhaseStepSourceAbility; import mage.abilities.condition.common.OnOpponentsTurnCondition; @@ -13,24 +9,23 @@ import mage.abilities.effects.RequirementEffect; import mage.abilities.effects.RestrictionEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.PhaseStep; -import mage.constants.TurnPhase; +import mage.constants.*; import mage.game.Game; import mage.game.permanent.Permanent; import mage.game.turn.Phase; import mage.game.turn.TurnMod; +import java.util.List; +import java.util.Objects; +import java.util.UUID; + /** - * * @author LevelX2 */ public final class IllusionistsGambit extends CardImpl { public IllusionistsGambit(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.INSTANT},"{2}{U}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{U}{U}"); // Cast Illusionist's Gambit only during the declare blockers step on an opponent's turn. this.addAbility(new CastOnlyDuringPhaseStepSourceAbility(PhaseStep.DECLARE_BLOCKERS, OnOpponentsTurnCondition.instance)); @@ -122,9 +117,7 @@ class IllusionistsGambitRequirementEffect extends RequirementEffect { @Override public boolean isInactive(Ability source, Game game) { if (game.getTurn().getStepType() == PhaseStep.END_COMBAT) { - if (!Objects.equals(game.getTurn().getPhase(), phase)) { - return true; - } + return !Objects.equals(game.getTurn().getPhase(), phase); } return false; } @@ -166,25 +159,23 @@ class IllusionistsGambitRestrictionEffect extends RestrictionEffect { @Override public boolean isInactive(Ability source, Game game) { if (game.getTurn().getStepType() == PhaseStep.END_COMBAT) { - if (!Objects.equals(game.getTurn().getPhase(), phase)) { - return true; - } + return !Objects.equals(game.getTurn().getPhase(), phase); } return false; } @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } if (defenderId.equals(source.getControllerId())) { return false; } // planeswalker Permanent permanent = game.getPermanent(defenderId); - if (permanent != null && permanent.isControlledBy(source.getControllerId()) - && permanent.isPlaneswalker()) { - return false; - } - return true; + return permanent == null || !permanent.isControlledBy(source.getControllerId()) + || !permanent.isPlaneswalker(); } @Override diff --git a/Mage.Sets/src/mage/cards/m/MoggToady.java b/Mage.Sets/src/mage/cards/m/MoggToady.java index 3b4d5277615..7ce51ffe812 100644 --- a/Mage.Sets/src/mage/cards/m/MoggToady.java +++ b/Mage.Sets/src/mage/cards/m/MoggToady.java @@ -1,7 +1,5 @@ - package mage.cards.m; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; @@ -9,29 +7,30 @@ import mage.abilities.effects.RestrictionEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.SubType; import mage.constants.Duration; +import mage.constants.SubType; import mage.constants.Zone; import mage.filter.common.FilterControlledCreaturePermanent; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; +import java.util.UUID; + /** - * * @author emerald000 & L_J */ public final class MoggToady extends CardImpl { public MoggToady(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{R}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{R}"); this.subtype.add(SubType.GOBLIN); this.power = new MageInt(2); this.toughness = new MageInt(2); // Mogg Toady can't attack unless you control more creatures than defending player. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new MoggToadyCantAttackEffect())); - + // Mogg Toady can't block unless you control more creatures than attacking player. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new MoggToadyCantBlockEffect())); } @@ -64,24 +63,25 @@ class MoggToadyCantAttackEffect extends RestrictionEffect { @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } + UUID defendingPlayerId; Player defender = game.getPlayer(defenderId); if (defender == null) { Permanent permanent = game.getPermanent(defenderId); if (permanent != null) { defendingPlayerId = permanent.getControllerId(); - } - else { + } else { return false; } - } - else { + } else { defendingPlayerId = defenderId; } if (defendingPlayerId != null) { return game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), source.getControllerId(), game) > game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), defendingPlayerId, game); - } - else { + } else { return true; } } diff --git a/Mage.Sets/src/mage/cards/m/MonstrousHound.java b/Mage.Sets/src/mage/cards/m/MonstrousHound.java index 06dc331a670..4cc6b545f6d 100644 --- a/Mage.Sets/src/mage/cards/m/MonstrousHound.java +++ b/Mage.Sets/src/mage/cards/m/MonstrousHound.java @@ -1,24 +1,24 @@ package mage.cards.m; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.Effect; import mage.abilities.effects.RestrictionEffect; -import mage.constants.SubType; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; +import mage.constants.SubType; import mage.constants.Zone; import mage.filter.common.FilterControlledLandPermanent; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; +import java.util.UUID; + /** - * * @author jeffwadsworth */ public final class MonstrousHound extends CardImpl { @@ -71,6 +71,10 @@ class CantAttackUnlessControllerControlsMoreLandsEffect extends RestrictionEffec @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } + UUID defendingPlayerId; Player defender = game.getPlayer(defenderId); if (defender == null) { diff --git a/Mage.Sets/src/mage/cards/t/TeferisMoat.java b/Mage.Sets/src/mage/cards/t/TeferisMoat.java index 0b80baa251a..c163287dc1a 100644 --- a/Mage.Sets/src/mage/cards/t/TeferisMoat.java +++ b/Mage.Sets/src/mage/cards/t/TeferisMoat.java @@ -1,7 +1,5 @@ - package mage.cards.t; -import java.util.UUID; import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldAbility; @@ -18,16 +16,17 @@ import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; +import java.util.UUID; + /** - * * @author Markedagain */ public final class TeferisMoat extends CardImpl { public TeferisMoat(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{3}{W}{U}"); - + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}{U}"); + // As Teferi's Moat enters the battlefield, choose a color. this.addAbility(new EntersBattlefieldAbility(new ChooseColorEffect(Outcome.Neutral))); // Creatures of the chosen color without flying can't attack you. @@ -46,15 +45,15 @@ public final class TeferisMoat extends CardImpl { class TeferisMoatRestrictionEffect extends RestrictionEffect { - TeferisMoatRestrictionEffect(){ + TeferisMoatRestrictionEffect() { super(Duration.WhileOnBattlefield, Outcome.Benefit); staticText = "Creatures of the chosen color without flying can't attack you"; } - + TeferisMoatRestrictionEffect(final TeferisMoatRestrictionEffect effect) { super(effect); } - + @Override public boolean applies(Permanent permanent, Ability source, Game game) { ObjectColor chosenColor = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color"); @@ -63,12 +62,15 @@ class TeferisMoatRestrictionEffect extends RestrictionEffect { permanent.getColor(game).shares(chosenColor) && permanent.isCreature(); } - + @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } return !defenderId.equals(source.getControllerId()); } - + @Override public TeferisMoatRestrictionEffect copy() { return new TeferisMoatRestrictionEffect(this); diff --git a/Mage.Sets/src/mage/cards/w/WebOfInertia.java b/Mage.Sets/src/mage/cards/w/WebOfInertia.java index 6739e5cf828..47a384bf8f3 100644 --- a/Mage.Sets/src/mage/cards/w/WebOfInertia.java +++ b/Mage.Sets/src/mage/cards/w/WebOfInertia.java @@ -1,7 +1,5 @@ - package mage.cards.w; -import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; import mage.abilities.Mode; @@ -12,18 +10,15 @@ import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.RestrictionEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.TargetController; -import mage.constants.Zone; +import mage.constants.*; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.common.TargetCardInYourGraveyard; +import java.util.UUID; + /** - * * @author Styxo */ public final class WebOfInertia extends CardImpl { @@ -110,6 +105,9 @@ class WebOfInertiaRestrictionEffect extends RestrictionEffect { @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } return !defenderId.equals(source.getControllerId()); } diff --git a/Mage.Sets/src/mage/cards/x/XantchaSleeperAgent.java b/Mage.Sets/src/mage/cards/x/XantchaSleeperAgent.java index 560d3acf922..f10a1339a4c 100644 --- a/Mage.Sets/src/mage/cards/x/XantchaSleeperAgent.java +++ b/Mage.Sets/src/mage/cards/x/XantchaSleeperAgent.java @@ -138,6 +138,10 @@ class XantchaSleeperAgentAttackRestrictionEffect extends RestrictionEffect { @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } + boolean allowAttack = true; UUID ownerPlayerId = source.getSourcePermanentIfItStillExists(game).getOwnerId(); diff --git a/Mage/src/main/java/mage/abilities/effects/RestrictionEffect.java b/Mage/src/main/java/mage/abilities/effects/RestrictionEffect.java index b1dc7e3a9eb..8ee2f8037c5 100644 --- a/Mage/src/main/java/mage/abilities/effects/RestrictionEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/RestrictionEffect.java @@ -1,7 +1,5 @@ - package mage.abilities.effects; -import java.util.UUID; import mage.abilities.Ability; import mage.constants.Duration; import mage.constants.EffectType; @@ -9,8 +7,9 @@ import mage.constants.Outcome; import mage.game.Game; import mage.game.permanent.Permanent; +import java.util.UUID; + /** - * * @author BetaSteward_at_googlemail.com */ public abstract class RestrictionEffect extends ContinuousEffectImpl { @@ -39,6 +38,13 @@ public abstract class RestrictionEffect extends ContinuousEffectImpl { return true; } + /** + * @param attacker + * @param defenderId id of planeswalker or player to attack, can be empty for general checks + * @param source + * @param game + * @return + */ public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { return true; } diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackControllerAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackControllerAttachedEffect.java index 09e122ede9e..3d7bceb932f 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackControllerAttachedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackControllerAttachedEffect.java @@ -1,8 +1,5 @@ - - package mage.abilities.effects.common.combat; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.RestrictionEffect; import mage.constants.AttachmentType; @@ -10,9 +7,10 @@ import mage.constants.Duration; import mage.game.Game; import mage.game.permanent.Permanent; +import java.util.UUID; + /** - * * @author LevelX2 */ @@ -34,6 +32,10 @@ public class CantAttackControllerAttachedEffect extends RestrictionEffect { @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } + if (defenderId.equals(source.getControllerId())) { return false; } diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackIfDefenderControlsPermanent.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackIfDefenderControlsPermanent.java index e813b23e8b2..9c1fdd30ccd 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackIfDefenderControlsPermanent.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackIfDefenderControlsPermanent.java @@ -1,8 +1,5 @@ - - package mage.abilities.effects.common.combat; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.RestrictionEffect; import mage.constants.Duration; @@ -11,8 +8,9 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; +import java.util.UUID; + /** - * * @author BursegSardaukar */ @@ -38,6 +36,10 @@ public class CantAttackIfDefenderControlsPermanent extends RestrictionEffect { @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } + UUID defendingPlayerId; Player player = game.getPlayer(defenderId); if (player == null) { diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackUnlessDefenderControllsPermanent.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackUnlessDefenderControllsPermanent.java index 91a597aaa20..5f46360b09a 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackUnlessDefenderControllsPermanent.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackUnlessDefenderControllsPermanent.java @@ -1,8 +1,5 @@ - - package mage.abilities.effects.common.combat; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.RestrictionEffect; import mage.constants.Duration; @@ -11,8 +8,9 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; +import java.util.UUID; + /** - * * @author LevelX2 */ @@ -38,6 +36,10 @@ public class CantAttackUnlessDefenderControllsPermanent extends RestrictionEffec @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } + UUID defendingPlayerId; Player player = game.getPlayer(defenderId); if (player == null) { @@ -50,10 +52,7 @@ public class CantAttackUnlessDefenderControllsPermanent extends RestrictionEffec } else { defendingPlayerId = defenderId; } - if (defendingPlayerId != null && game.getBattlefield().countAll(filter, defendingPlayerId, game) == 0) { - return false; - } - return true; + return defendingPlayerId == null || game.getBattlefield().countAll(filter, defendingPlayerId, game) != 0; } @Override diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouAllEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouAllEffect.java index 1fc2dd1d2aa..d5da3b814a2 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouAllEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouAllEffect.java @@ -1,4 +1,3 @@ - package mage.abilities.effects.common.combat; import mage.abilities.Ability; @@ -13,7 +12,6 @@ import mage.game.permanent.Permanent; import java.util.UUID; /** - * * @author LevelX2 */ public class CantAttackYouAllEffect extends RestrictionEffect { @@ -51,6 +49,9 @@ public class CantAttackYouAllEffect extends RestrictionEffect { @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } if (alsoPlaneswalker) { Permanent planeswalker = game.getPermanent(defenderId); if (planeswalker != null) { diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouEffect.java index 7214238747f..aa3f911ed8d 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouEffect.java @@ -1,15 +1,14 @@ - package mage.abilities.effects.common.combat; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.RestrictionEffect; import mage.constants.Duration; import mage.game.Game; import mage.game.permanent.Permanent; +import java.util.UUID; + /** - * * @author TheElk801 */ public class CantAttackYouEffect extends RestrictionEffect { @@ -34,6 +33,9 @@ public class CantAttackYouEffect extends RestrictionEffect { @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } return !defenderId.equals(source.getControllerId()); } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouOrPlaneswalkerAllEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouOrPlaneswalkerAllEffect.java index b603326ddff..67c01bacbbd 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouOrPlaneswalkerAllEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/CantAttackYouOrPlaneswalkerAllEffect.java @@ -1,7 +1,5 @@ - package mage.abilities.effects.common.combat; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.RestrictionEffect; import mage.constants.Duration; @@ -10,8 +8,9 @@ import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.game.permanent.Permanent; +import java.util.UUID; + /** - * * @author fireshoes */ public class CantAttackYouOrPlaneswalkerAllEffect extends RestrictionEffect { @@ -40,6 +39,10 @@ public class CantAttackYouOrPlaneswalkerAllEffect extends RestrictionEffect { @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } + if (defenderId.equals(source.getControllerId())) { return false; } diff --git a/Mage/src/main/java/mage/game/command/planes/AgyremPlane.java b/Mage/src/main/java/mage/game/command/planes/AgyremPlane.java index df6166cc6e7..69b767cf39d 100644 --- a/Mage/src/main/java/mage/game/command/planes/AgyremPlane.java +++ b/Mage/src/main/java/mage/game/command/planes/AgyremPlane.java @@ -1,9 +1,5 @@ - package mage.game.command.planes; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.ActivateIfConditionActivatedAbility; @@ -33,8 +29,11 @@ import mage.target.Target; import mage.target.targetpointer.FixedTarget; import mage.watchers.common.PlanarRollWatcher; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + /** - * * @author spjspj */ public class AgyremPlane extends Plane { @@ -152,6 +151,10 @@ class AgyremRestrictionEffect extends RestrictionEffect { @Override public boolean canAttack(Permanent attacker, UUID defenderId, Ability source, Game game) { + if (defenderId == null) { + return true; + } + Plane cPlane = game.getState().getCurrentPlane(); if (cPlane != null && cPlane.getName().equalsIgnoreCase("Plane - Agyrem")) { return !defenderId.equals(source.getControllerId());