From a089b70d649c2cfd207b49a6100fa8a97643d70e Mon Sep 17 00:00:00 2001 From: dilnu Date: Sun, 9 Feb 2020 13:40:26 -0500 Subject: [PATCH] Use getSourceObjectIfItStillExists. --- .../common/PutOnLibrarySourceEffect.java | 35 +++++++++---------- ...vealAndShuffleIntoLibrarySourceEffect.java | 2 +- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Mage/src/main/java/mage/abilities/effects/common/PutOnLibrarySourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/PutOnLibrarySourceEffect.java index ce7c44b71f5..cd7f43bddb8 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/PutOnLibrarySourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/PutOnLibrarySourceEffect.java @@ -1,6 +1,7 @@ package mage.abilities.effects.common; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.Mode; import mage.abilities.effects.OneShotEffect; @@ -43,25 +44,23 @@ public class PutOnLibrarySourceEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - boolean result = false; - switch (game.getState().getZone(source.getSourceId())) { - case BATTLEFIELD: - Permanent permanent = game.getPermanent(source.getSourceId()); - if (permanent != null && source.getSourceObjectZoneChangeCounter() == permanent.getZoneChangeCounter(game)) { - result |= permanent.moveToZone(Zone.LIBRARY, source.getSourceId(), game, onTop); - } - case GRAVEYARD: - Card card = game.getCard(source.getSourceId()); - if (card != null && source.getSourceObjectZoneChangeCounter() == card.getZoneChangeCounter(game)) { - for (Player player : game.getPlayers().values()) { - if (player.getGraveyard().contains(card.getId())) { - player.getGraveyard().remove(card); - result |= card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, onTop); - } - } - } + MageObject sourceObject = source.getSourceObjectIfItStillExists(game); + if (sourceObject == null) { + return false; } - return result; + if (sourceObject instanceof Permanent) { + ((Permanent) sourceObject).moveToZone(Zone.LIBRARY, source.getSourceId(), game, onTop); + return true; + } else if (sourceObject instanceof Card && game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) { + for (Player player : game.getPlayers().values()) { + if (player.getGraveyard().contains(sourceObject.getId())) { + player.getGraveyard().remove(((Card) sourceObject)); + ((Card) sourceObject).moveToZone(Zone.LIBRARY, source.getSourceId(), game, onTop); + return true; + } + } + } + return false; } @Override diff --git a/Mage/src/main/java/mage/abilities/effects/common/RevealAndShuffleIntoLibrarySourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/RevealAndShuffleIntoLibrarySourceEffect.java index 18fb81369b4..d14a23b5154 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/RevealAndShuffleIntoLibrarySourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/RevealAndShuffleIntoLibrarySourceEffect.java @@ -34,7 +34,7 @@ public class RevealAndShuffleIntoLibrarySourceEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - MageObject sourceObject = game.getObject(source.getSourceId()); + MageObject sourceObject = source.getSourceObjectIfItStillExists(game); Player controller = game.getPlayer(source.getControllerId()); if (sourceObject != null && controller != null) { Player owner = null;