Fixed NPE errors in canAttack restrict checks;

This commit is contained in:
Oleg Agafonov 2019-02-08 17:30:47 +04:00
parent dd2cf5a939
commit 454d76e30b
17 changed files with 128 additions and 106 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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) {

View file

@ -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

View file

@ -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) {

View file

@ -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());
}
}

View file

@ -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;
}

View file

@ -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());