diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index 1bdb9ecefc..ef3f411c73 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -3639,7 +3639,7 @@ public class TestPlayer implements Player { } @Override - public Set moveCardsToGraveyardWithInfo(Set allCards, Ability source, Game game, Zone fromZone) { + public Set moveCardsToGraveyardWithInfo(Set allCards, Ability source, Game game, Zone fromZone) { return computerPlayer.moveCardsToGraveyardWithInfo(allCards, source, game, fromZone); } @@ -4067,14 +4067,14 @@ public class TestPlayer implements Player { } @Override - public boolean moveCards(Set cards, Zone toZone, + public boolean moveCards(Set cards, Zone toZone, Ability source, Game game ) { return computerPlayer.moveCards(cards, toZone, source, game); } @Override - public boolean moveCards(Set cards, Zone toZone, + public boolean moveCards(Set cards, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects ) { diff --git a/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java b/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java index 78fd6b9859..fd808bb715 100644 --- a/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java +++ b/Mage.Tests/src/test/java/org/mage/test/stub/PlayerStub.java @@ -1161,12 +1161,12 @@ public class PlayerStub implements Player { } @Override - public boolean moveCards(Set cards, Zone toZone, Ability source, Game game) { + public boolean moveCards(Set cards, Zone toZone, Ability source, Game game) { return false; } @Override - public boolean moveCards(Set cards, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects) { + public boolean moveCards(Set cards, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects) { return false; } @@ -1196,7 +1196,7 @@ public class PlayerStub implements Player { } @Override - public Set moveCardsToGraveyardWithInfo(Set cards, Ability source, Game game, Zone fromZone) { + public Set moveCardsToGraveyardWithInfo(Set cards, Ability source, Game game, Zone fromZone) { return null; } diff --git a/Mage/src/main/java/mage/cards/Cards.java b/Mage/src/main/java/mage/cards/Cards.java index a6c6a21efc..43601cda35 100644 --- a/Mage/src/main/java/mage/cards/Cards.java +++ b/Mage/src/main/java/mage/cards/Cards.java @@ -1,13 +1,13 @@ - package mage.cards; +import mage.filter.FilterCard; +import mage.game.Game; + import java.io.Serializable; import java.util.Collection; import java.util.List; import java.util.Set; import java.util.UUID; -import mage.filter.FilterCard; -import mage.game.Game; public interface Cards extends Set, Serializable { @@ -19,9 +19,9 @@ public interface Cards extends Set, Serializable { void setOwner(UUID ownerId, Game game); - void addAll(List createCards); + void addAll(List createCards); - void addAll(Set createCards); + void addAll(Set createCards); Set getCards(Game game); diff --git a/Mage/src/main/java/mage/cards/CardsImpl.java b/Mage/src/main/java/mage/cards/CardsImpl.java index 6433768b79..1823a8f3f1 100644 --- a/Mage/src/main/java/mage/cards/CardsImpl.java +++ b/Mage/src/main/java/mage/cards/CardsImpl.java @@ -1,5 +1,6 @@ package mage.cards; +import mage.MageItem; import mage.MageObject; import mage.filter.FilterCard; import mage.game.Game; @@ -28,10 +29,12 @@ public class CardsImpl extends LinkedHashSet implements Cards, Serializabl } } - public CardsImpl(Set cards) { - for (Card card : cards) { - this.add(card.getId()); - } + public CardsImpl(List cards) { + this.addAll(cards); + } + + public CardsImpl(Set cards) { + this.addAll(cards); } public CardsImpl(Collection cardIds) { @@ -172,16 +175,22 @@ public class CardsImpl extends LinkedHashSet implements Cards, Serializabl } @Override - public void addAll(List cards) { - for (Card card : cards) { - add(card.getId()); + public void addAll(List cards) { + if (cards != null) { + cards.stream() + .filter(Objects::nonNull) + .map(MageItem::getId) + .forEach(this::add); } } @Override - public void addAll(Set cards) { - for (Card card : cards) { - add(card.getId()); + public void addAll(Set cards) { + if (cards != null) { + cards.stream() + .filter(Objects::nonNull) + .map(MageItem::getId) + .forEach(this::add); } } diff --git a/Mage/src/main/java/mage/players/Player.java b/Mage/src/main/java/mage/players/Player.java index 1973dde6ab..39c5a0c678 100644 --- a/Mage/src/main/java/mage/players/Player.java +++ b/Mage/src/main/java/mage/players/Player.java @@ -807,7 +807,7 @@ public interface Player extends MageItem, Copyable { boolean moveCards(Card card, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects); - boolean moveCards(Set cards, Zone toZone, Ability source, Game game); + boolean moveCards(Set cards, Zone toZone, Ability source, Game game); /** * Universal method to move cards from one zone to another. Do not mix @@ -826,7 +826,7 @@ public interface Player extends MageItem, Copyable { * @param appliedEffects * @return */ - boolean moveCards(Set cards, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects); + boolean moveCards(Set cards, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects); boolean moveCardsToExile(Card card, Ability source, Game game, boolean withName, UUID exileId, String exileZoneName); @@ -883,7 +883,7 @@ public interface Player extends MageItem, Copyable { * @param fromZone if null, this info isn't postet * @return Set that were successful moved to graveyard */ - Set moveCardsToGraveyardWithInfo(Set cards, Ability source, Game game, Zone fromZone); + Set moveCardsToGraveyardWithInfo(Set cards, Ability source, Game game, Zone fromZone); /** * Uses card.moveToZone and posts a inform message about moving the card to diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 98f4ade265..6594ad0897 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -4097,14 +4097,14 @@ public abstract class PlayerImpl implements Player, Serializable { } @Override - public boolean moveCards(Set cards, Zone toZone, + public boolean moveCards(Set cards, Zone toZone, Ability source, Game game ) { return moveCards(cards, toZone, source, game, false, false, false, null); } @Override - public boolean moveCards(Set cards, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects) { + public boolean moveCards(Set cards, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, List appliedEffects) { if (cards.isEmpty()) { return true; } @@ -4248,13 +4248,13 @@ public abstract class PlayerImpl implements Player, Serializable { } @Override - public Set moveCardsToGraveyardWithInfo(Set allCards, Ability source, Game game, Zone fromZone) { + public Set moveCardsToGraveyardWithInfo(Set allCards, Ability source, Game game, Zone fromZone) { Set movedCards = new LinkedHashSet<>(); while (!allCards.isEmpty()) { // identify cards from one owner Cards cards = new CardsImpl(); UUID ownerId = null; - for (Iterator it = allCards.iterator(); it.hasNext(); ) { + for (Iterator it = allCards.iterator(); it.hasNext(); ) { Card card = it.next(); if (cards.isEmpty()) { ownerId = card.getOwnerId();