mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Fixed multiple NPE errors in cards;
This commit is contained in:
parent
285ed5801f
commit
105062beb7
14 changed files with 104 additions and 94 deletions
|
@ -25,6 +25,7 @@ import mage.players.Player;
|
|||
import mage.target.TargetSpell;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -133,10 +134,17 @@ class AshioksErasureReplacementEffect extends ContinuousRuleModifyingEffectImpl
|
|||
exile = game.getExile().getExileZone(exileZone);
|
||||
}
|
||||
}
|
||||
|
||||
if (exile == null) {
|
||||
return false;
|
||||
}
|
||||
Card exiledCard = exile.getCards(game).iterator().next();
|
||||
|
||||
Set<Card> cards = exile.getCards(game);
|
||||
if (cards.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Card exiledCard = cards.iterator().next();
|
||||
if (exiledCard != null) {
|
||||
return exiledCard.getName().equals(card.getName());
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package mage.cards.a;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
|
@ -19,8 +17,10 @@ import mage.game.Game;
|
|||
import mage.players.Player;
|
||||
import mage.target.TargetCard;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jeffwadsworth
|
||||
*/
|
||||
public final class AugurOfBolas extends CardImpl {
|
||||
|
@ -81,9 +81,12 @@ class AugurOfBolasEffect extends OneShotEffect {
|
|||
int number = topCards.count(new FilterInstantOrSorceryCard(), source.getSourceId(), source.getControllerId(), game);
|
||||
if (number > 0) {
|
||||
if (controller.chooseUse(outcome, "Reveal an instant or sorcery card from the looked at cards and put it into your hand?", source, game)) {
|
||||
Card card;
|
||||
Card card = null;
|
||||
if (number == 1) {
|
||||
card = topCards.getCards(new FilterInstantOrSorceryCard(), source.getSourceId(), source.getControllerId(), game).iterator().next();
|
||||
Set<Card> cards = topCards.getCards(new FilterInstantOrSorceryCard(), source.getSourceId(), source.getControllerId(), game);
|
||||
if (!cards.isEmpty()) {
|
||||
card = cards.iterator().next();
|
||||
}
|
||||
} else {
|
||||
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterInstantOrSorceryCard());
|
||||
controller.chooseTarget(outcome, topCards, target, source, game);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package mage.cards.c;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
|
@ -16,8 +14,10 @@ import mage.players.Player;
|
|||
import mage.target.TargetCard;
|
||||
import mage.target.common.TargetCardInLibrary;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public final class Cultivate extends CardImpl {
|
||||
|
@ -79,12 +79,14 @@ class CultivateEffect extends OneShotEffect {
|
|||
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
|
||||
revealed.remove(card);
|
||||
}
|
||||
card = revealed.getCards(game).iterator().next();
|
||||
Set<Card> cards = revealed.getCards(game);
|
||||
card = cards.isEmpty() ? null : cards.iterator().next();
|
||||
if (card != null) {
|
||||
controller.moveCards(card, Zone.HAND, source, game);
|
||||
}
|
||||
} else if (target.getTargets().size() == 1) {
|
||||
Card card = revealed.getCards(game).iterator().next();
|
||||
Set<Card> cards = revealed.getCards(game);
|
||||
Card card = cards.isEmpty() ? null : cards.iterator().next();
|
||||
if (card != null) {
|
||||
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
|
||||
}
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
|
||||
package mage.cards.f;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.cards.*;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
|
@ -18,8 +12,10 @@ import mage.players.Player;
|
|||
import mage.target.TargetCard;
|
||||
import mage.target.common.TargetCardInLibrary;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TheElk801
|
||||
*/
|
||||
public final class FinalParting extends CardImpl {
|
||||
|
@ -78,10 +74,12 @@ class FinalPartingEffect extends OneShotEffect {
|
|||
Card card = searched.get(target2.getFirstTarget(), game);
|
||||
controller.moveCards(card, Zone.HAND, source, game);
|
||||
searched.remove(card);
|
||||
card = searched.getCards(game).iterator().next();
|
||||
Set<Card> cards = searched.getCards(game);
|
||||
card = cards.isEmpty() ? null : cards.iterator().next();
|
||||
controller.moveCards(card, Zone.GRAVEYARD, source, game);
|
||||
} else if (target.getTargets().size() == 1) {
|
||||
Card card = searched.getCards(game).iterator().next();
|
||||
Set<Card> cards = searched.getCards(game);
|
||||
Card card = cards.isEmpty() ? null : cards.iterator().next();
|
||||
controller.moveCards(card, Zone.HAND, source, game);
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ class GodEternalKefnetDrawCardReplacementEffect extends ReplacementEffectImpl {
|
|||
return false;
|
||||
}
|
||||
|
||||
Card topCard = you.getLibrary().getTopCards(game, 1).iterator().next();
|
||||
Card topCard = you.getLibrary().getFromTop(game);
|
||||
if (topCard == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
|
||||
package mage.cards.j;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.cards.*;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
|
@ -19,8 +13,10 @@ import mage.players.Player;
|
|||
import mage.target.TargetCard;
|
||||
import mage.target.common.TargetCardInLibrary;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class JaradsOrders extends CardImpl {
|
||||
|
@ -41,6 +37,7 @@ public final class JaradsOrders extends CardImpl {
|
|||
return new JaradsOrders(this);
|
||||
}
|
||||
}
|
||||
|
||||
class JaradsOrdersEffect extends OneShotEffect {
|
||||
|
||||
protected static final FilterCard filter = new FilterCard("card to put into your hand");
|
||||
|
@ -78,10 +75,12 @@ class JaradsOrdersEffect extends OneShotEffect {
|
|||
Card card = revealed.get(target2.getFirstTarget(), game);
|
||||
controller.moveCards(card, Zone.HAND, source, game);
|
||||
revealed.remove(card);
|
||||
card = revealed.getCards(game).iterator().next();
|
||||
Set<Card> cards = revealed.getCards(game);
|
||||
card = cards.isEmpty() ? null : cards.iterator().next();
|
||||
controller.moveCards(card, Zone.GRAVEYARD, source, game);
|
||||
} else if (target.getTargets().size() == 1) {
|
||||
Card card = revealed.getCards(game).iterator().next();
|
||||
Set<Card> cards = revealed.getCards(game);
|
||||
Card card = cards.isEmpty() ? null : cards.iterator().next();
|
||||
controller.moveCards(card, Zone.HAND, source, game);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.cards.k;
|
||||
|
||||
import mage.MageObject;
|
||||
|
@ -16,10 +15,10 @@ import mage.players.Player;
|
|||
import mage.target.TargetCard;
|
||||
import mage.target.common.TargetCardInLibrary;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class KodamasReach extends CardImpl {
|
||||
|
@ -84,12 +83,14 @@ class KodamasReachEffect extends OneShotEffect {
|
|||
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
|
||||
revealed.remove(card);
|
||||
}
|
||||
card = revealed.getCards(game).iterator().next();
|
||||
Set<Card> cards = revealed.getCards(game);
|
||||
card = cards.isEmpty() ? null : cards.iterator().next();
|
||||
if (card != null) {
|
||||
controller.moveCards(card, Zone.HAND, source, game);
|
||||
}
|
||||
} else if (target.getTargets().size() == 1) {
|
||||
Card card = revealed.getCards(game).iterator().next();
|
||||
Set<Card> cards = revealed.getCards(game);
|
||||
Card card = cards.isEmpty() ? null : cards.iterator().next();
|
||||
if (card != null) {
|
||||
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
|
||||
package mage.cards.m;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.DelayedTriggeredAbility;
|
||||
|
@ -11,21 +8,19 @@ import mage.abilities.costs.common.SacrificeSourceCost;
|
|||
import mage.abilities.costs.common.TapSourceCost;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.cards.*;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author HCrescent
|
||||
*/
|
||||
public final class MagusOfTheJar extends CardImpl {
|
||||
|
@ -73,9 +68,9 @@ class MagusoftheJarEffect extends OneShotEffect {
|
|||
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
Cards hand = player.getHand();
|
||||
while (!hand.isEmpty()) {
|
||||
Card card = hand.get(hand.iterator().next(), game);
|
||||
Cards handCards = new CardsImpl(player.getHand());
|
||||
for (UUID cardId : handCards) {
|
||||
Card card = handCards.get(cardId, game);
|
||||
if (card != null) {
|
||||
card.moveToExile(getId(), "Magus of the Jar", source.getSourceId(), game);
|
||||
card.setFaceDown(true, game);
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
|
||||
package mage.cards.m;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.DelayedTriggeredAbility;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
|
@ -10,11 +7,7 @@ import mage.abilities.costs.common.SacrificeSourceCost;
|
|||
import mage.abilities.costs.common.TapSourceCost;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.cards.*;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
|
@ -23,8 +16,10 @@ import mage.game.events.GameEvent;
|
|||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Plopman
|
||||
*/
|
||||
public final class MemoryJar extends CardImpl {
|
||||
|
@ -69,9 +64,9 @@ class MemoryJarEffect extends OneShotEffect {
|
|||
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
Cards hand = player.getHand();
|
||||
while (!hand.isEmpty()) {
|
||||
Card card = hand.get(hand.iterator().next(), game);
|
||||
Cards handCards = new CardsImpl(player.getHand());
|
||||
for (UUID cardId : handCards) {
|
||||
Card card = handCards.get(cardId, game);
|
||||
if (card != null) {
|
||||
card.moveToExile(getId(), "Memory Jar", source.getSourceId(), game);
|
||||
card.setFaceDown(true, game);
|
||||
|
|
|
@ -17,6 +17,7 @@ import mage.players.Player;
|
|||
import mage.target.TargetCard;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -83,7 +84,8 @@ class OathOfNissaEffect extends OneShotEffect {
|
|||
if (controller.chooseUse(outcome, "Reveal a creature, land, or planeswalker card from the looked at cards and put it into your hand?", source, game)) {
|
||||
Card card;
|
||||
if (number == 1) {
|
||||
card = topCards.getCards(filter, source.getSourceId(), source.getControllerId(), game).iterator().next();
|
||||
Set<Card> cards = topCards.getCards(filter, source.getSourceId(), source.getControllerId(), game);
|
||||
card = cards.isEmpty() ? null : cards.iterator().next();
|
||||
} else {
|
||||
TargetCard target = new TargetCard(Zone.LIBRARY, filter);
|
||||
controller.choose(outcome, topCards, target, game);
|
||||
|
|
|
@ -1,22 +1,17 @@
|
|||
package mage.cards.p;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.ReplacementEffectImpl;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.cards.*;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.game.ExileZone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
|
@ -26,8 +21,11 @@ import mage.target.common.TargetCardInLibrary;
|
|||
import mage.util.CardUtil;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jeffwadsworth
|
||||
*/
|
||||
public final class ParallelThoughts extends CardImpl {
|
||||
|
@ -131,10 +129,11 @@ class ParallelThoughtsReplacementEffect extends ReplacementEffectImpl {
|
|||
@Override
|
||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null
|
||||
&& !game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source)).getCards(game).isEmpty()) {
|
||||
ExileZone exileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
|
||||
Set<Card> cards = exileZone != null ? exileZone.getCards(game) : null;
|
||||
if (controller != null && cards != null && !cards.isEmpty()) {
|
||||
if (controller.chooseUse(outcome, "Draw a card from the pile you exiled instead drawing from your library?", source, game)) {
|
||||
Card card = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source)).getCards(game).iterator().next();
|
||||
Card card = cards.iterator().next();
|
||||
if (card != null) {
|
||||
controller.moveCards(card, Zone.HAND, source, game);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.cards.p;
|
||||
|
||||
import mage.MageObject;
|
||||
|
@ -17,10 +16,10 @@ import mage.players.Player;
|
|||
import mage.target.TargetCard;
|
||||
import mage.target.common.TargetCardInLibrary;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class Peregrination extends CardImpl {
|
||||
|
@ -85,10 +84,12 @@ class PeregrinationEffect extends OneShotEffect {
|
|||
Card card = revealed.get(target2.getFirstTarget(), game);
|
||||
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
|
||||
revealed.remove(card);
|
||||
card = revealed.getCards(game).iterator().next();
|
||||
Set<Card> cards = revealed.getCards(game);
|
||||
card = cards.isEmpty() ? null : cards.iterator().next();
|
||||
controller.moveCards(card, Zone.HAND, source, game);
|
||||
} else if (target.getTargets().size() == 1) {
|
||||
Card card = revealed.getCards(game).iterator().next();
|
||||
Set<Card> cards = revealed.getCards(game);
|
||||
Card card = cards.isEmpty() ? null : cards.iterator().next();
|
||||
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
|
@ -13,9 +11,11 @@ import mage.game.permanent.Permanent;
|
|||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
*
|
||||
*/
|
||||
public class HideawayPlayEffect extends OneShotEffect {
|
||||
|
||||
|
@ -41,11 +41,15 @@ public class HideawayPlayEffect extends OneShotEffect {
|
|||
zone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), permanent.getZoneChangeCounter(game)));
|
||||
}
|
||||
|
||||
if (zone == null
|
||||
|| zone.isEmpty()) {
|
||||
if (zone == null) {
|
||||
return true;
|
||||
}
|
||||
Card card = zone.getCards(game).iterator().next();
|
||||
Set<Card> cards = zone.getCards(game);
|
||||
if (cards.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Card card = cards.iterator().next();
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (card != null && controller != null) {
|
||||
if (controller.chooseUse(Outcome.PlayForFree, "Do you want to play " + card.getIdName() + " for free now?", source, game)) {
|
||||
|
|
|
@ -285,6 +285,9 @@ public final class ZonesHandler {
|
|||
|
||||
public static List<Card> chooseOrder(String message, Cards cards, Player player, Game game) {
|
||||
List<Card> order = new ArrayList<>();
|
||||
if (cards.isEmpty()) {
|
||||
return order;
|
||||
}
|
||||
TargetCard target = new TargetCard(Zone.ALL, new FilterCard(message));
|
||||
target.setRequired(true);
|
||||
while (player.isInGame() && cards.size() > 1) {
|
||||
|
|
Loading…
Reference in a new issue