mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
Merge pull request #5161 from Dilnu/Kindred
Make the type checking on predicates added to filters stricter
This commit is contained in:
commit
a68667e582
11 changed files with 50 additions and 32 deletions
|
|
@ -18,7 +18,7 @@ public interface Filter<E> extends Serializable {
|
|||
|
||||
boolean match(E o, Game game);
|
||||
|
||||
Filter<E> add(Predicate predicate);
|
||||
Filter<E> add(Predicate<? super E> predicate);
|
||||
|
||||
boolean checkObjectClass(Object object);
|
||||
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@ import mage.game.Game;
|
|||
*/
|
||||
public abstract class FilterImpl<E> implements Filter<E> {
|
||||
|
||||
protected List<Predicate<Object>> predicates = new ArrayList<>();
|
||||
protected List<Predicate<? super E>> predicates = new ArrayList<>();
|
||||
protected String message;
|
||||
protected boolean lockedFilter; // Helps to prevent to "accidently" modify the StaticFilters objects
|
||||
protected boolean lockedFilter; // Helps to prevent "accidentally" modifying the StaticFilters objects
|
||||
|
||||
@Override
|
||||
public abstract FilterImpl<E> copy();
|
||||
|
|
@ -41,7 +41,7 @@ public abstract class FilterImpl<E> implements Filter<E> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public final Filter add(Predicate predicate) {
|
||||
public final Filter add(Predicate<? super E> predicate) {
|
||||
if (isLockedFilter()) {
|
||||
throw new UnsupportedOperationException("You may not modify a locked filter");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@
|
|||
package mage.filter.common;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.keyword.SuspendAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.counters.CounterType;
|
||||
|
|
@ -46,7 +48,7 @@ import mage.game.permanent.Permanent;
|
|||
*
|
||||
* @author emerald000
|
||||
*/
|
||||
public class FilterPermanentOrSuspendedCard extends FilterImpl<Object> implements FilterInPlay<Object> {
|
||||
public class FilterPermanentOrSuspendedCard extends FilterImpl<MageObject> implements FilterInPlay<MageObject> {
|
||||
|
||||
protected FilterCard cardFilter;
|
||||
protected FilterPermanent permanentFilter;
|
||||
|
|
@ -71,11 +73,11 @@ public class FilterPermanentOrSuspendedCard extends FilterImpl<Object> implement
|
|||
|
||||
@Override
|
||||
public boolean checkObjectClass(Object object) {
|
||||
return true;
|
||||
return object instanceof MageObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(Object o, Game game) {
|
||||
public boolean match(MageObject o, Game game) {
|
||||
if (o instanceof Permanent) {
|
||||
return permanentFilter.match((Permanent) o, game);
|
||||
} else if (o instanceof Card) {
|
||||
|
|
@ -85,7 +87,7 @@ public class FilterPermanentOrSuspendedCard extends FilterImpl<Object> implement
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean match(Object o, UUID sourceId, UUID playerId, Game game) {
|
||||
public boolean match(MageObject o, UUID sourceId, UUID playerId, Game game) {
|
||||
if (o instanceof Permanent) {
|
||||
return permanentFilter.match((Permanent) o, sourceId, playerId, game);
|
||||
} else if (o instanceof Card) {
|
||||
|
|
@ -106,7 +108,7 @@ public class FilterPermanentOrSuspendedCard extends FilterImpl<Object> implement
|
|||
this.permanentFilter = permanentFilter;
|
||||
}
|
||||
|
||||
public void setSpellFilter(FilterCard cardFilter) {
|
||||
public void setCardFilter(FilterCard cardFilter) {
|
||||
this.cardFilter = cardFilter;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,10 +30,14 @@
|
|||
package mage.filter.common;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.filter.FilterImpl;
|
||||
import mage.filter.FilterInPlay;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.FilterSpell;
|
||||
import mage.filter.predicate.ObjectPlayer;
|
||||
import mage.filter.predicate.ObjectPlayerPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.Spell;
|
||||
|
|
@ -42,7 +46,7 @@ import mage.game.stack.Spell;
|
|||
*
|
||||
* @author LevelX
|
||||
*/
|
||||
public class FilterSpellOrPermanent extends FilterImpl<Object> implements FilterInPlay<Object> {
|
||||
public class FilterSpellOrPermanent extends FilterImpl<MageObject> implements FilterInPlay<MageObject> {
|
||||
|
||||
protected FilterPermanent permanentFilter;
|
||||
protected FilterSpell spellFilter;
|
||||
|
|
@ -65,11 +69,11 @@ public class FilterSpellOrPermanent extends FilterImpl<Object> implements Filter
|
|||
|
||||
@Override
|
||||
public boolean checkObjectClass(Object object) {
|
||||
return true;
|
||||
return object instanceof MageObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean match(Object o, Game game) {
|
||||
public boolean match(MageObject o, Game game) {
|
||||
if (o instanceof Spell) {
|
||||
return spellFilter.match((Spell) o, game);
|
||||
} else if (o instanceof Permanent) {
|
||||
|
|
@ -79,7 +83,7 @@ public class FilterSpellOrPermanent extends FilterImpl<Object> implements Filter
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean match(Object o, UUID sourceId, UUID playerId, Game game) {
|
||||
public boolean match(MageObject o, UUID sourceId, UUID playerId, Game game) {
|
||||
if (o instanceof Spell) {
|
||||
return spellFilter.match((Spell) o, sourceId, playerId, game);
|
||||
} else if (o instanceof Permanent) {
|
||||
|
|
@ -88,11 +92,19 @@ public class FilterSpellOrPermanent extends FilterImpl<Object> implements Filter
|
|||
return false;
|
||||
}
|
||||
|
||||
public final void add(ObjectPlayerPredicate<? extends ObjectPlayer> predicate) {
|
||||
if (isLockedFilter()) {
|
||||
throw new UnsupportedOperationException("You may not modify a locked filter");
|
||||
}
|
||||
spellFilter.add(predicate);
|
||||
permanentFilter.add(predicate);
|
||||
}
|
||||
|
||||
public FilterPermanent getPermanentFilter() {
|
||||
return this.permanentFilter;
|
||||
}
|
||||
|
||||
public FilterSpell getspellFilter() {
|
||||
public FilterSpell getSpellFilter() {
|
||||
return this.spellFilter;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import java.util.UUID;
|
|||
import mage.MageObject;
|
||||
import mage.abilities.Mode;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.game.Controllable;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.target.Target;
|
||||
|
|
@ -13,7 +14,7 @@ import mage.target.Target;
|
|||
*
|
||||
* @author jeffwadsworth
|
||||
*/
|
||||
public class NumberOfTargetsPredicate implements Predicate<MageObject> {
|
||||
public class NumberOfTargetsPredicate implements Predicate<Controllable> {
|
||||
|
||||
private final int targets;
|
||||
|
||||
|
|
@ -22,7 +23,7 @@ public class NumberOfTargetsPredicate implements Predicate<MageObject> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(MageObject input, Game game) {
|
||||
public boolean apply(Controllable input, Game game) {
|
||||
StackObject stackObject = game.getState().getStack().getStackObject(input.getId());
|
||||
if (stackObject != null) {
|
||||
int numberOfTargets = 0;
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class TargetPermanentOrSuspendedCard extends TargetImpl {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Filter<Object> getFilter() {
|
||||
public Filter<MageObject> getFilter() {
|
||||
return this.filter;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue