Make the type checking on predicates added to filters stricter to make runtime errors less likely.

This commit is contained in:
dilnu 2018-07-21 23:25:52 -04:00
parent 9705f7228c
commit a8cd19eaea
11 changed files with 50 additions and 32 deletions

View file

@ -18,6 +18,7 @@ import mage.counters.Counter;
import mage.counters.CounterType;
import mage.filter.Filter;
import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.CardCounterPredicate;
import mage.filter.predicate.permanent.CounterPredicate;
import mage.game.Game;
@ -59,13 +60,13 @@ public final class DustOfMoments extends CardImpl {
public abstract static class DustOfMomentsEffect extends OneShotEffect {
private final Counter counter;
private final Filter<Card> permFilter;
private final Filter<Permanent> permFilter;
private final Filter<Card> exiledFilter;
public DustOfMomentsEffect() {
super(Outcome.Benefit);
this.counter = new Counter(CounterType.TIME.getName(), 2);
this.permFilter = new FilterCard("permanent and each suspended card");
this.permFilter = new FilterPermanent("permanent and each suspended card");
permFilter.add(new CounterPredicate(CounterType.TIME));
this.exiledFilter = new FilterCard("permanent and each suspended card");

View file

@ -55,15 +55,15 @@ public final class Interdict extends CardImpl {
}
}
class InterdictPredicate implements Predicate<Ability> {
class InterdictPredicate implements Predicate<StackObject> {
public InterdictPredicate() {
}
@Override
public boolean apply(Ability input, Game game) {
if (input instanceof StackAbility && input.getAbilityType() == AbilityType.ACTIVATED) {
MageObject sourceObject = input.getSourceObject(game);
public boolean apply(StackObject input, Game game) {
if (input instanceof StackAbility && ((StackAbility) input).getAbilityType() == AbilityType.ACTIVATED) {
MageObject sourceObject = ((StackAbility) input).getSourceObject(game);
if (sourceObject != null) {
return (sourceObject.isArtifact()
|| sourceObject.isEnchantment()

View file

@ -61,15 +61,16 @@ public final class OupheVandals extends CardImpl {
}
}
class ArtifactSourcePredicate implements Predicate<Ability> {
class ArtifactSourcePredicate implements Predicate<StackObject> {
public ArtifactSourcePredicate() {
}
@Override
public boolean apply(Ability input, Game game) {
public boolean apply(StackObject input, Game game) {
if (input instanceof StackAbility) {
return input.getSourceObject(game).isArtifact() && input.getAbilityType() == AbilityType.ACTIVATED;
StackAbility ability = (StackAbility) input;
return ability.getSourceObject(game).isArtifact() && ability.getAbilityType() == AbilityType.ACTIVATED;
}
return false;
}

View file

@ -10,7 +10,7 @@ import mage.constants.CardType;
import mage.filter.FilterSpell;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.target.TargetSpell;
import mage.watchers.common.CastSpellLastTurnWatcher;
@ -45,10 +45,10 @@ public final class SecondGuess extends CardImpl {
}
}
class SecondSpellPredicate implements Predicate<Spell> {
class SecondSpellPredicate implements Predicate<StackObject> {
@Override
public boolean apply(Spell input, Game game) {
public boolean apply(StackObject input, Game game) {
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
if (watcher.getSpellOrder(new MageObjectReference(input.getId(), game), game) == 2) {

View file

@ -12,6 +12,7 @@ import mage.filter.FilterSpell;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
/**
*
@ -43,7 +44,7 @@ public final class SecretsOfTheDead extends CardImpl {
}
}
class SpellZonePredicate implements Predicate<Spell> {
class SpellZonePredicate implements Predicate<StackObject> {
private final Zone zone;
@ -52,8 +53,8 @@ class SpellZonePredicate implements Predicate<Spell> {
}
@Override
public boolean apply(Spell input, Game game) {
return input.getFromZone().match(zone);
public boolean apply(StackObject input, Game game) {
return input instanceof Spell && ((Spell) input).getFromZone().match(zone);
}
@Override