From 90a41a10e7d3e5d0c34e5166bf418efc56c41627 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 25 Jul 2013 19:05:58 +0200 Subject: [PATCH] Fixed NPE in TopLibraryCardTypeCondition (fixes #300). --- .../common/TopLibraryCardTypeCondition.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Mage/src/mage/abilities/condition/common/TopLibraryCardTypeCondition.java b/Mage/src/mage/abilities/condition/common/TopLibraryCardTypeCondition.java index 0a87dad7c9..32cc030127 100644 --- a/Mage/src/mage/abilities/condition/common/TopLibraryCardTypeCondition.java +++ b/Mage/src/mage/abilities/condition/common/TopLibraryCardTypeCondition.java @@ -31,6 +31,7 @@ import mage.constants.CardType; import mage.abilities.Ability; import mage.abilities.condition.Condition; import mage.game.Game; +import mage.players.Player; /** * @author jeffwadsworth @@ -50,19 +51,22 @@ public class TopLibraryCardTypeCondition implements Condition { @Override public boolean apply(Game game, Ability source) { boolean conditionApplies = false; - switch (this.type) { - case CREATURE: - conditionApplies |= game.getPlayer(source.getControllerId()).getLibrary().getFromTop(game).getCardType().contains(CardType.CREATURE); - break; - case LAND: - conditionApplies |= game.getPlayer(source.getControllerId()).getLibrary().getFromTop(game).getCardType().contains(CardType.LAND); - break; - case SORCERY: - conditionApplies |= game.getPlayer(source.getControllerId()).getLibrary().getFromTop(game).getCardType().contains(CardType.SORCERY); - break; - case INSTANT: - conditionApplies |= game.getPlayer(source.getControllerId()).getLibrary().getFromTop(game).getCardType().contains(CardType.INSTANT); - break; + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null && controller.getLibrary().size() > 0) { + switch (this.type) { + case CREATURE: + conditionApplies |= controller.getLibrary().getFromTop(game).getCardType().contains(CardType.CREATURE); + break; + case LAND: + conditionApplies |= controller.getLibrary().getFromTop(game).getCardType().contains(CardType.LAND); + break; + case SORCERY: + conditionApplies |= controller.getLibrary().getFromTop(game).getCardType().contains(CardType.SORCERY); + break; + case INSTANT: + conditionApplies |= controller.getLibrary().getFromTop(game).getCardType().contains(CardType.INSTANT); + break; + } } return conditionApplies; }