Fixed NPE errors in canBlock restrict checks;

This commit is contained in:
Oleg Agafonov 2019-02-09 02:48:11 +04:00
parent 454d76e30b
commit 60a0ec03c0
18 changed files with 86 additions and 69 deletions

View file

@ -1,7 +1,5 @@
package mage.cards.c;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAllTriggeredAbility;
@ -10,11 +8,7 @@ import mage.abilities.effects.RestrictionEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.constants.*;
import mage.counters.CounterType;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
@ -22,6 +16,8 @@ import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
* @author noxx
*/
@ -79,7 +75,7 @@ class ChampionOfLambholtEffect extends RestrictionEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null && attacker.isControlledBy(sourcePermanent.getControllerId())) {
if (sourcePermanent != null && attacker != null && attacker.isControlledBy(sourcePermanent.getControllerId())) {
return blocker.getPower().getValue() >= sourcePermanent.getPower().getValue();
}
return true;

View file

@ -1,7 +1,5 @@
package mage.cards.c;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.RestrictionEffect;
@ -20,8 +18,9 @@ import mage.filter.predicate.mageobject.AbilityPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
*
* @author jeffwadsworth
*/
public final class Chaosphere extends CardImpl {
@ -80,6 +79,9 @@ class ChaosphereEffect extends RestrictionEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
return attacker.hasAbility(FlyingAbility.getInstance().getId(), game);
}

View file

@ -1,7 +1,5 @@
package mage.cards.d;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.RestrictionEffect;
@ -16,14 +14,15 @@ import mage.filter.predicate.mageobject.AbilityPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public final class DenseCanopy extends CardImpl {
public DenseCanopy(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{G}");
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{G}");
// Creatures with flying can block only creatures with flying.
@ -64,6 +63,9 @@ class DenseCanopyCantBlockEffect extends RestrictionEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
return attacker.hasAbility(FlyingAbility.getInstance().getId(), game);
}

View file

@ -1,7 +1,5 @@
package mage.cards.e;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
@ -12,14 +10,15 @@ import mage.abilities.keyword.TrampleAbility;
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 Styxo
*/
public final class Exogorth extends CardImpl {
@ -84,6 +83,9 @@ class CanBlockOnlySpaceflightEffect extends RestrictionEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
return attacker.getAbilities().contains(SpaceflightAbility.getInstance());
}

View file

@ -111,6 +111,9 @@ class GoblinGoonCantBlockEffect extends RestrictionEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
UUID attackingPlayerId = attacker.getControllerId();
if (attackingPlayerId != null) {
return game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), source.getControllerId(), game) > game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), attackingPlayerId, game);

View file

@ -1,7 +1,5 @@
package mage.cards.i;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.common.AttachEffect;
@ -10,19 +8,15 @@ import mage.abilities.effects.common.continuous.BoostEnchantedEffect;
import mage.abilities.keyword.EnchantAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.AttachmentType;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.constants.*;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
*
* @author L_J
*/
public final class IronclawCurse extends CardImpl {
@ -73,6 +67,9 @@ class IronclawCurseEffect extends CantBlockAttachedEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
Permanent enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (enchantment == null) {
return false;

View file

@ -1,7 +1,5 @@
package mage.cards.m;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AttacksTriggeredAbility;
@ -14,20 +12,14 @@ import mage.abilities.effects.common.AddContinuousEffectToGame;
import mage.abilities.keyword.FirstStrikeAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.constants.SuperType;
import mage.constants.Zone;
import mage.constants.*;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import java.util.UUID;
/**
*
* @author TheElk801
*/
public final class MirriWeatherlightDuelist extends CardImpl {
@ -87,6 +79,9 @@ class MirriWeatherlightDuelistBlockRestrictionEffect extends RestrictionEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
for (UUID creature : game.getCombat().getBlockers()) {
if (game.getPlayer(game.getPermanent(creature).getOwnerId()).hasOpponent(attacker.getControllerId(), game)) {
return false;

View file

@ -110,6 +110,9 @@ class MoggToadyCantBlockEffect extends RestrictionEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
UUID attackingPlayerId = attacker.getControllerId();
if (attackingPlayerId != null) {
return game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), source.getControllerId(), game) > game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), attackingPlayerId, game);

View file

@ -119,6 +119,9 @@ class CantBlockUnlessControllerControlsMoreLandsEffect extends RestrictionEffect
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
UUID attackingPlayerId = attacker.getControllerId();
if (attackingPlayerId != null) {
return game.getBattlefield().countAll(new FilterControlledLandPermanent(),

View file

@ -1,7 +1,5 @@
package mage.cards.s;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
@ -13,19 +11,15 @@ import mage.abilities.keyword.PartnerAbility;
import mage.abilities.keyword.ReachAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.ComparisonType;
import mage.constants.Duration;
import mage.constants.SuperType;
import mage.constants.Zone;
import mage.constants.*;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.PowerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public final class SidarKondoOfJamuraa extends CardImpl {
@ -92,9 +86,12 @@ class SidarKondoOfJamuraaCantBlockCreaturesSourceEffect extends RestrictionEffec
}
return game.getOpponents(source.getControllerId()).contains(permanent.getControllerId());
}
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
return !filter.match(attacker, source.getSourceId(), source.getControllerId(), game);
}

View file

@ -1,7 +1,5 @@
package mage.cards.s;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
@ -9,18 +7,15 @@ import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.ColoredManaCost;
import mage.abilities.effects.RestrictionEffect;
import mage.abilities.effects.common.continuous.BoostSourceEffect;
import mage.constants.SubType;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.ColoredManaSymbol;
import mage.constants.Duration;
import mage.constants.Zone;
import mage.constants.*;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.UUID;
/**
*
* @author TheElk801
*/
public final class SpitfireHandler extends CardImpl {
@ -67,6 +62,9 @@ class SpitfireHandlerCantBlockEffect extends RestrictionEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
return (blocker.getPower().getValue() >= attacker.getPower().getValue());
}

View file

@ -53,6 +53,13 @@ public abstract class RestrictionEffect extends ContinuousEffectImpl {
return true;
}
/**
* @param attacker can be empty for general checks
* @param blocker
* @param source
* @param game
* @return
*/
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
return true;
}

View file

@ -1,5 +1,3 @@
package mage.abilities.effects.common.combat;
import mage.abilities.Ability;
@ -32,6 +30,9 @@ public class CanBlockOnlyFlyingAttachedEffect extends RestrictionEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
return attacker.getAbilities().contains(FlyingAbility.getInstance());
}

View file

@ -1,5 +1,3 @@
package mage.abilities.effects.common.combat;
import mage.abilities.Ability;
@ -10,7 +8,6 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
@ -33,6 +30,9 @@ public class CanBlockOnlyFlyingEffect extends RestrictionEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
return attacker.getAbilities().contains(FlyingAbility.getInstance());
}

View file

@ -1,18 +1,17 @@
package mage.abilities.effects.common.combat;
import mage.abilities.Ability;
import mage.abilities.effects.RestrictionEffect;
import mage.constants.AttachmentType;
import mage.constants.Duration;
import static mage.constants.Duration.EndOfTurn;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
import static mage.constants.Duration.EndOfTurn;
/**
*
* @author North
*/
public class CantBlockAttachedEffect extends RestrictionEffect {
@ -70,6 +69,9 @@ public class CantBlockAttachedEffect extends RestrictionEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
return !filter.match(attacker, source.getSourceId(), source.getControllerId(), game);
}

View file

@ -37,6 +37,9 @@ public class CantBlockCreaturesSourceEffect extends RestrictionEffect {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
return !filter.match(attacker, source.getSourceId(), source.getControllerId(), game);
}

View file

@ -1,6 +1,5 @@
package mage.abilities.keyword;
import java.io.ObjectStreamException;
import mage.abilities.Ability;
import mage.abilities.EvasionAbility;
import mage.abilities.MageSingleton;
@ -10,6 +9,8 @@ import mage.constants.Duration;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.io.ObjectStreamException;
/**
* "Shadow" keyword
*
@ -60,6 +61,9 @@ class ShadowEffect extends RestrictionEffect implements MageSingleton {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
return attacker.getAbilities().containsKey(ShadowAbility.getInstance().getId());
}

View file

@ -1,7 +1,5 @@
package mage.abilities.keyword;
import java.io.ObjectStreamException;
import mage.abilities.Ability;
import mage.abilities.EvasionAbility;
import mage.abilities.MageSingleton;
@ -10,8 +8,9 @@ import mage.constants.Duration;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.io.ObjectStreamException;
/**
*
* @author Styxo
*/
public class SpaceflightAbility extends EvasionAbility implements MageSingleton {
@ -59,6 +58,9 @@ class SpaceFlightEffect extends RestrictionEffect implements MageSingleton {
@Override
public boolean canBlock(Permanent attacker, Permanent blocker, Ability source, Game game) {
if (attacker == null) {
return true;
}
return attacker.getAbilities().containsKey(SpaceflightAbility.getInstance().getId());
}