* ManaSpentToCastWatcher - Fixed possible null pointer exception.

This commit is contained in:
LevelX2 2015-09-06 22:14:35 +02:00
parent b8f0c38101
commit 7aa27a9800

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.watchers.common; package mage.watchers.common;
import mage.Mana; import mage.Mana;
@ -58,16 +57,16 @@ public class ManaSpentToCastWatcher extends Watcher {
@Override @Override
public void watch(GameEvent event, Game game) { public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST && event.getZone() == Zone.HAND) { if (event.getType() == GameEvent.EventType.SPELL_CAST && event.getZone() == Zone.HAND) {
Spell spell = (Spell) game.getObject(event.getTargetId()); Spell spell = (Spell) game.getObject(event.getTargetId());
if (this.getSourceId().equals(spell.getSourceId())) { if (spell != null && this.getSourceId().equals(spell.getSourceId())) {
payment = spell.getSpellAbility().getManaCostsToPay().getPayment(); payment = spell.getSpellAbility().getManaCostsToPay().getPayment();
} }
} }
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && this.getSourceId().equals(event.getSourceId())) { if (event.getType() == GameEvent.EventType.ZONE_CHANGE && this.getSourceId().equals(event.getSourceId())) {
if (((ZoneChangeEvent) event).getFromZone().equals(Zone.BATTLEFIELD)) { if (((ZoneChangeEvent) event).getFromZone().equals(Zone.BATTLEFIELD)) {
payment = null; payment = null;
} }
} }
} }