diff --git a/Mage/src/main/java/mage/filter/FilterCard.java b/Mage/src/main/java/mage/filter/FilterCard.java index f3c8f0c372..0ae6b64360 100644 --- a/Mage/src/main/java/mage/filter/FilterCard.java +++ b/Mage/src/main/java/mage/filter/FilterCard.java @@ -1,10 +1,8 @@ package mage.filter; import mage.cards.Card; -import mage.filter.predicate.ObjectPlayer; -import mage.filter.predicate.ObjectPlayerPredicate; -import mage.filter.predicate.ObjectSourcePlayer; -import mage.filter.predicate.Predicates; +import mage.constants.TargetController; +import mage.filter.predicate.*; import mage.game.Game; import java.util.ArrayList; @@ -71,6 +69,9 @@ public class FilterCard extends FilterObject { if (isLockedFilter()) { throw new UnsupportedOperationException("You may not modify a locked filter"); } + + checkPredicateIsSuitableForCardFilter(predicate); + extraPredicates.add(predicate); } @@ -86,4 +87,13 @@ public class FilterCard extends FilterObject { public FilterCard copy() { return new FilterCard(this); } + + public static void checkPredicateIsSuitableForCardFilter(Predicate predicate) { + // card filter can't contain controller predicate (only permanents on battlefield have controller) + List list = new ArrayList<>(); + Predicates.collectAllComponents(predicate, list); + if (list.stream().anyMatch(p -> p instanceof TargetController.ControllerPredicate)) { + throw new IllegalArgumentException("Card filter doesn't support controller predicate"); + } + } }