From b632d89caa259b7f1e30926b4ca4a2068629cc2f Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sun, 26 Mar 2023 13:10:00 +0400 Subject: [PATCH] Refactor: fixed wrong usage of getSourceObjectIfItStillExists (fixed error "cannot be cast to Permanent"); --- Mage.Sets/src/mage/cards/b/BishopOfBinding.java | 2 +- Mage.Sets/src/mage/cards/c/ChaosLord.java | 2 +- Mage.Sets/src/mage/cards/c/ColfenorsUrn.java | 2 +- Mage.Sets/src/mage/cards/c/CrovaxTheCursed.java | 2 +- Mage.Sets/src/mage/cards/e/EntrailsFeaster.java | 2 +- Mage.Sets/src/mage/cards/f/FlameKinWarScout.java | 2 +- Mage.Sets/src/mage/cards/f/FruitcakeElemental.java | 2 +- Mage.Sets/src/mage/cards/g/GOTOJAIL.java | 4 ++-- Mage.Sets/src/mage/cards/g/GoblinCadets.java | 2 +- Mage.Sets/src/mage/cards/g/GravePeril.java | 2 +- Mage.Sets/src/mage/cards/h/HumbleDefector.java | 2 +- Mage.Sets/src/mage/cards/h/HungryHungryHeifer.java | 2 +- Mage.Sets/src/mage/cards/j/JarJarBinks.java | 2 +- Mage.Sets/src/mage/cards/j/JinxedChoker.java | 2 +- Mage.Sets/src/mage/cards/j/JinxedRing.java | 2 +- Mage.Sets/src/mage/cards/m/Magmasaur.java | 2 +- Mage.Sets/src/mage/cards/m/MeasureOfWickedness.java | 2 +- Mage.Sets/src/mage/cards/m/MissDemeanor.java | 2 +- Mage.Sets/src/mage/cards/p/PrimordialOoze.java | 2 +- Mage.Sets/src/mage/cards/s/SleeperAgent.java | 2 +- Mage.Sets/src/mage/cards/w/WitchEngine.java | 2 +- Mage.Sets/src/mage/cards/y/YawgmothDemon.java | 2 +- Mage/src/main/java/mage/abilities/common/LicidAbility.java | 4 ++-- .../common/combat/MustBeBlockedByTargetSourceEffect.java | 2 +- 24 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Mage.Sets/src/mage/cards/b/BishopOfBinding.java b/Mage.Sets/src/mage/cards/b/BishopOfBinding.java index dbf0717195c..ba8519aeb0f 100644 --- a/Mage.Sets/src/mage/cards/b/BishopOfBinding.java +++ b/Mage.Sets/src/mage/cards/b/BishopOfBinding.java @@ -81,7 +81,7 @@ class BishopOfBindingExileEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); // If this leaves the battlefield before its triggered ability resolves, // the target creature won't be exiled. if (permanent != null) { diff --git a/Mage.Sets/src/mage/cards/c/ChaosLord.java b/Mage.Sets/src/mage/cards/c/ChaosLord.java index 994971dcdf5..d7207e677ad 100644 --- a/Mage.Sets/src/mage/cards/c/ChaosLord.java +++ b/Mage.Sets/src/mage/cards/c/ChaosLord.java @@ -122,7 +122,7 @@ class GainControlSourceEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); if (permanent != null) { return permanent.changeControllerId(source.getFirstTarget(), game, source); } else { diff --git a/Mage.Sets/src/mage/cards/c/ColfenorsUrn.java b/Mage.Sets/src/mage/cards/c/ColfenorsUrn.java index da26d1ad12f..0acfd163d1a 100644 --- a/Mage.Sets/src/mage/cards/c/ColfenorsUrn.java +++ b/Mage.Sets/src/mage/cards/c/ColfenorsUrn.java @@ -76,7 +76,7 @@ class ColfenorsUrnEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); if (controller != null && permanent != null) { UUID exileId = CardUtil.getCardExileZoneId(game, source); ExileZone exile = game.getExile().getExileZone(exileId); diff --git a/Mage.Sets/src/mage/cards/c/CrovaxTheCursed.java b/Mage.Sets/src/mage/cards/c/CrovaxTheCursed.java index 4b325c0d0dc..5f0a165a741 100644 --- a/Mage.Sets/src/mage/cards/c/CrovaxTheCursed.java +++ b/Mage.Sets/src/mage/cards/c/CrovaxTheCursed.java @@ -77,7 +77,7 @@ class CrovaxTheCursedEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent sourceObject = source.getSourcePermanentIfItStillExists(game); int creatures = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game); if (creatures > 0 && controller.chooseUse(outcome, "Sacrifice a creature?", source, game)) { if (new SacrificeControllerEffect(StaticFilters.FILTER_PERMANENT_CREATURES, 1, "").apply(game, source)) { diff --git a/Mage.Sets/src/mage/cards/e/EntrailsFeaster.java b/Mage.Sets/src/mage/cards/e/EntrailsFeaster.java index cb01061c6f6..7c17f7aa02d 100644 --- a/Mage.Sets/src/mage/cards/e/EntrailsFeaster.java +++ b/Mage.Sets/src/mage/cards/e/EntrailsFeaster.java @@ -67,7 +67,7 @@ class EntrailsFeasterEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null && source.getSourceId() != null) { - Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent sourceObject = source.getSourcePermanentIfItStillExists(game); TargetCardInGraveyard target = new TargetCardInGraveyard(filter); target.setNotTarget(true); if (target.canChoose(controller.getId(), source, game) && controller.chooseUse(outcome, "Exile a creature card from a graveyard?", source, game)) { diff --git a/Mage.Sets/src/mage/cards/f/FlameKinWarScout.java b/Mage.Sets/src/mage/cards/f/FlameKinWarScout.java index 5787ae25a7a..5accde322e5 100644 --- a/Mage.Sets/src/mage/cards/f/FlameKinWarScout.java +++ b/Mage.Sets/src/mage/cards/f/FlameKinWarScout.java @@ -73,7 +73,7 @@ class FlameKinWarScourEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); if (permanent != null) { if (permanent.sacrifice(source, game)) { Effect effect = new DamageTargetEffect(4).setText("{this} deals 4 damage to it"); diff --git a/Mage.Sets/src/mage/cards/f/FruitcakeElemental.java b/Mage.Sets/src/mage/cards/f/FruitcakeElemental.java index 251b9263265..b71300ac015 100644 --- a/Mage.Sets/src/mage/cards/f/FruitcakeElemental.java +++ b/Mage.Sets/src/mage/cards/f/FruitcakeElemental.java @@ -80,7 +80,7 @@ class FruitcakeElementalEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); Player player = game.getPlayer(getTargetPointer().getFirst(game, source)); if (player != null && permanent != null) { ContinuousEffect effect = new FruitcakeElementalControlSourceEffect(); diff --git a/Mage.Sets/src/mage/cards/g/GOTOJAIL.java b/Mage.Sets/src/mage/cards/g/GOTOJAIL.java index 9738c4e4c28..2a5e96172bf 100644 --- a/Mage.Sets/src/mage/cards/g/GOTOJAIL.java +++ b/Mage.Sets/src/mage/cards/g/GOTOJAIL.java @@ -72,7 +72,7 @@ class GoToJailExileEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source)); // If GO TO JAIL leaves the battlefield before its triggered ability resolves, @@ -134,7 +134,7 @@ class GoToJailUpkeepEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { MageObject sourceObject = source.getSourceObjectIfItStillExists(game); - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); if (sourceObject instanceof Permanent && permanent != null) { diff --git a/Mage.Sets/src/mage/cards/g/GoblinCadets.java b/Mage.Sets/src/mage/cards/g/GoblinCadets.java index 89921ec5275..6f13241d9e6 100644 --- a/Mage.Sets/src/mage/cards/g/GoblinCadets.java +++ b/Mage.Sets/src/mage/cards/g/GoblinCadets.java @@ -60,7 +60,7 @@ class GoblinCadetsChangeControlEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); if (permanent != null) { return permanent.changeControllerId(source.getFirstTarget(), game, source); } else { diff --git a/Mage.Sets/src/mage/cards/g/GravePeril.java b/Mage.Sets/src/mage/cards/g/GravePeril.java index 111fe52a78b..ade65e0bcbf 100644 --- a/Mage.Sets/src/mage/cards/g/GravePeril.java +++ b/Mage.Sets/src/mage/cards/g/GravePeril.java @@ -57,7 +57,7 @@ class GravePerilEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); if (permanent != null) { if (permanent.sacrifice(source, game)) { Effect effect = new DestroyTargetEffect(); diff --git a/Mage.Sets/src/mage/cards/h/HumbleDefector.java b/Mage.Sets/src/mage/cards/h/HumbleDefector.java index a57f69b0df6..cfe07456c67 100644 --- a/Mage.Sets/src/mage/cards/h/HumbleDefector.java +++ b/Mage.Sets/src/mage/cards/h/HumbleDefector.java @@ -71,7 +71,7 @@ class HumbleDefectorEffect extends OneShotEffect { if (controller != null) { controller.drawCards(2, source, game); } - Permanent humbleDefector = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent humbleDefector = source.getSourcePermanentIfItStillExists(game); Player targetOpponent = game.getPlayer(getTargetPointer().getFirst(game, source)); if (targetOpponent != null && humbleDefector != null) { ContinuousEffect effect = new HumbleDefectorControlSourceEffect(); diff --git a/Mage.Sets/src/mage/cards/h/HungryHungryHeifer.java b/Mage.Sets/src/mage/cards/h/HungryHungryHeifer.java index 0fb9eb007ce..2bc73a28b12 100644 --- a/Mage.Sets/src/mage/cards/h/HungryHungryHeifer.java +++ b/Mage.Sets/src/mage/cards/h/HungryHungryHeifer.java @@ -68,7 +68,7 @@ class HungryHungryHeiferEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent sourceObject = source.getSourcePermanentIfItStillExists(game); if (sourceObject != null && controller != null) { if (controller.chooseUse(outcome, "Remove a counter from a permanent you control?", source, game)) { TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true); diff --git a/Mage.Sets/src/mage/cards/j/JarJarBinks.java b/Mage.Sets/src/mage/cards/j/JarJarBinks.java index ba0b5207421..8b1364ce9ca 100644 --- a/Mage.Sets/src/mage/cards/j/JarJarBinks.java +++ b/Mage.Sets/src/mage/cards/j/JarJarBinks.java @@ -75,7 +75,7 @@ class JarJarBinksEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Permanent jarJar = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent jarJar = source.getSourcePermanentIfItStillExists(game); Player player = game.getPlayer(source.getControllerId()); Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source)); if (player != null && jarJar != null && opponent != null) { diff --git a/Mage.Sets/src/mage/cards/j/JinxedChoker.java b/Mage.Sets/src/mage/cards/j/JinxedChoker.java index 9dbd749c7b0..f647a4551ed 100644 --- a/Mage.Sets/src/mage/cards/j/JinxedChoker.java +++ b/Mage.Sets/src/mage/cards/j/JinxedChoker.java @@ -76,7 +76,7 @@ class JinxedChokerChangeControllerEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); if (permanent != null) { return permanent.changeControllerId(source.getFirstTarget(), game, source); } else { diff --git a/Mage.Sets/src/mage/cards/j/JinxedRing.java b/Mage.Sets/src/mage/cards/j/JinxedRing.java index 2b769713e4d..d8c54682b69 100644 --- a/Mage.Sets/src/mage/cards/j/JinxedRing.java +++ b/Mage.Sets/src/mage/cards/j/JinxedRing.java @@ -78,7 +78,7 @@ class JinxedRingEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); if (permanent != null) { return permanent.changeControllerId(source.getFirstTarget(), game, source); } else { diff --git a/Mage.Sets/src/mage/cards/m/Magmasaur.java b/Mage.Sets/src/mage/cards/m/Magmasaur.java index dd7c794154f..e21cab45b88 100644 --- a/Mage.Sets/src/mage/cards/m/Magmasaur.java +++ b/Mage.Sets/src/mage/cards/m/Magmasaur.java @@ -81,7 +81,7 @@ class MagmasaurEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent sourceObject = source.getSourcePermanentIfItStillExists(game); if (sourceObject != null && controller != null) { if (controller.chooseUse(outcome, "Remove a +1/+1 counter from " + sourceObject.getLogName() + '?', source, game)) { sourceObject.removeCounters(CounterType.P1P1.getName(), 1, source, game); diff --git a/Mage.Sets/src/mage/cards/m/MeasureOfWickedness.java b/Mage.Sets/src/mage/cards/m/MeasureOfWickedness.java index 0bcfd0d637c..3e7bc372dd6 100644 --- a/Mage.Sets/src/mage/cards/m/MeasureOfWickedness.java +++ b/Mage.Sets/src/mage/cards/m/MeasureOfWickedness.java @@ -85,7 +85,7 @@ class MeasureOfWickednessControlSourceEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { Player targetOpponent = game.getPlayer(source.getFirstTarget()); - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); if (permanent != null && targetOpponent != null) { permanent.changeControllerId(targetOpponent.getId(), game, source); } else { diff --git a/Mage.Sets/src/mage/cards/m/MissDemeanor.java b/Mage.Sets/src/mage/cards/m/MissDemeanor.java index 923af90cdd8..5449720812f 100644 --- a/Mage.Sets/src/mage/cards/m/MissDemeanor.java +++ b/Mage.Sets/src/mage/cards/m/MissDemeanor.java @@ -71,7 +71,7 @@ class MissDemeanorEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent sourceObject = source.getSourcePermanentIfItStillExists(game); String activePlayerName = game.getPlayer(game.getActivePlayerId()).getName(); if (sourceObject != null) { if (controller.chooseUse(outcome, "Compliment " + activePlayerName + " on their game play?", source, game)) { diff --git a/Mage.Sets/src/mage/cards/p/PrimordialOoze.java b/Mage.Sets/src/mage/cards/p/PrimordialOoze.java index 9da9df1fae4..7ea6d76318c 100644 --- a/Mage.Sets/src/mage/cards/p/PrimordialOoze.java +++ b/Mage.Sets/src/mage/cards/p/PrimordialOoze.java @@ -66,7 +66,7 @@ class PrimordialOozeEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent sourceObject = source.getSourcePermanentIfItStillExists(game); if (controller != null && sourceObject != null) { int counter = sourceObject.getCounters(game).getCount(CounterType.P1P1); Cost cost = new ManaCostsImpl<>("{" + counter + '}'); diff --git a/Mage.Sets/src/mage/cards/s/SleeperAgent.java b/Mage.Sets/src/mage/cards/s/SleeperAgent.java index 38ad6e0df9e..33ec6225590 100644 --- a/Mage.Sets/src/mage/cards/s/SleeperAgent.java +++ b/Mage.Sets/src/mage/cards/s/SleeperAgent.java @@ -70,7 +70,7 @@ class SleeperAgentChangeControlEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); if (permanent != null) { return permanent.changeControllerId(source.getFirstTarget(), game, source); } else { diff --git a/Mage.Sets/src/mage/cards/w/WitchEngine.java b/Mage.Sets/src/mage/cards/w/WitchEngine.java index 9391692c0bd..4a1efef9304 100644 --- a/Mage.Sets/src/mage/cards/w/WitchEngine.java +++ b/Mage.Sets/src/mage/cards/w/WitchEngine.java @@ -73,7 +73,7 @@ class WitchEngineEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - Permanent permanent = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent permanent = source.getSourcePermanentIfItStillExists(game); if (permanent != null) { return permanent.changeControllerId(source.getFirstTarget(), game, source); } else { diff --git a/Mage.Sets/src/mage/cards/y/YawgmothDemon.java b/Mage.Sets/src/mage/cards/y/YawgmothDemon.java index dbc0c266458..9da4abb03cf 100644 --- a/Mage.Sets/src/mage/cards/y/YawgmothDemon.java +++ b/Mage.Sets/src/mage/cards/y/YawgmothDemon.java @@ -76,7 +76,7 @@ class YawgmothDemonEffect extends OneShotEffect { } } if (!artifactSacrificed) { - Permanent sourceObject = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent sourceObject = source.getSourcePermanentIfItStillExists(game); if (sourceObject != null) { sourceObject.tap(source, game); controller.damage(2, source.getSourceId(), source, game); diff --git a/Mage/src/main/java/mage/abilities/common/LicidAbility.java b/Mage/src/main/java/mage/abilities/common/LicidAbility.java index d3bbb4940a1..2c84fe04787 100644 --- a/Mage/src/main/java/mage/abilities/common/LicidAbility.java +++ b/Mage/src/main/java/mage/abilities/common/LicidAbility.java @@ -66,7 +66,7 @@ class LicidEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Permanent licid = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent licid = source.getSourcePermanentIfItStillExists(game); if (licid != null) { UUID messageId = UUID.randomUUID(); LicidContinuousEffect effect = new LicidContinuousEffect(messageId); @@ -103,7 +103,7 @@ class LicidContinuousEffect extends ContinuousEffectImpl { @Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { - Permanent licid = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent licid = source.getSourcePermanentIfItStillExists(game); if (licid != null) { switch (layer) { case TypeChangingEffects_4: diff --git a/Mage/src/main/java/mage/abilities/effects/common/combat/MustBeBlockedByTargetSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/combat/MustBeBlockedByTargetSourceEffect.java index 33a093eca3f..3f6474e6172 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/combat/MustBeBlockedByTargetSourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/combat/MustBeBlockedByTargetSourceEffect.java @@ -34,7 +34,7 @@ public class MustBeBlockedByTargetSourceEffect extends RequirementEffect { if (permanent.getId().equals(this.getTargetPointer().getFirst(game, source))) { Permanent blocker = game.getPermanent(this.getTargetPointer().getFirst(game, source)); if (blocker != null && blocker.canBlock(source.getSourceId(), game)) { - Permanent attacker = (Permanent) source.getSourceObjectIfItStillExists(game); + Permanent attacker = source.getSourcePermanentIfItStillExists(game); if (attacker != null) { BlockedAttackerWatcher blockedAttackerWatcher = game.getState().getWatcher(BlockedAttackerWatcher.class); if (blockedAttackerWatcher != null && blockedAttackerWatcher.creatureHasBlockedAttacker(attacker, blocker, game)) {