From 63718e7a6e71a93c9dd89dd0051b8f7bf05a5597 Mon Sep 17 00:00:00 2001 From: Ingmar Goudt Date: Sat, 2 Feb 2019 22:09:55 +0100 Subject: [PATCH] Sonar fixes remove the deprecated GameState.getWatchers() --- .../src/mage/player/human/HumanPlayer.java | 2 +- Mage.Sets/src/mage/cards/a/AbunaAcolyte.java | 4 ++-- Mage.Sets/src/mage/cards/a/AccursedHorde.java | 4 ++-- .../src/mage/cards/a/AdmiralBeckettBrass.java | 9 +++----- .../src/mage/cards/a/AeronautTinkerer.java | 4 ++-- .../src/mage/cards/a/AetherMeltdown.java | 4 ++-- Mage.Sets/src/mage/cards/a/AetherStorm.java | 9 +++----- Mage.Sets/src/mage/cards/a/AjanisAid.java | 4 ++-- Mage.Sets/src/mage/cards/a/AllSunsDawn.java | 23 +++++++++---------- Mage.Sets/src/mage/cards/a/ArchiveTrap.java | 4 ++-- .../src/mage/cards/a/AwakenTheErstwhile.java | 8 +++---- Mage.Sets/src/mage/cards/b/BlazingEffigy.java | 2 +- Mage.Sets/src/mage/cards/c/ConduitOfRuin.java | 3 +-- .../src/mage/cards/c/CustodiSoulcaller.java | 2 +- Mage.Sets/src/mage/cards/f/FaithsReward.java | 8 +++++-- .../src/mage/cards/g/GeneratorServant.java | 12 ++++++---- Mage.Sets/src/mage/cards/g/GisaAndGeralf.java | 2 +- .../src/mage/cards/g/GlyphOfDelusion.java | 2 +- .../mage/cards/g/GlyphOfReincarnation.java | 2 +- .../src/mage/cards/i/IchneumonDruid.java | 2 +- .../mage/cards/m/MetamorphicAlteration.java | 2 +- Mage.Sets/src/mage/cards/o/OpalPalace.java | 12 ++++++---- Mage.Sets/src/mage/cards/q/Quicken.java | 4 ++-- Mage.Sets/src/mage/cards/t/TimeToReflect.java | 2 +- .../src/mage/cards/t/TreasureNabber.java | 1 - .../src/mage/cards/v/VizierOfDeferment.java | 4 ++-- Mage/src/main/java/mage/game/GameState.java | 5 ---- .../java/mage/game/GameTinyLeadersImpl.java | 2 +- 28 files changed, 70 insertions(+), 72 deletions(-) diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index 2de7065cf1..04dabbd016 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -146,7 +146,7 @@ public class HumanPlayer extends PlayerImpl { protected boolean pullResponseFromQueue(Game game) { if (actionQueue.isEmpty() && actionIterations > 0 && !actionQueueSaved.isEmpty()) { - actionQueue = new LinkedList(actionQueueSaved); + actionQueue = new LinkedList<>(actionQueueSaved); actionIterations--; // logger.info("MACRO iteration: " + actionIterations); } diff --git a/Mage.Sets/src/mage/cards/a/AbunaAcolyte.java b/Mage.Sets/src/mage/cards/a/AbunaAcolyte.java index 63f6f8c100..187ee463f8 100644 --- a/Mage.Sets/src/mage/cards/a/AbunaAcolyte.java +++ b/Mage.Sets/src/mage/cards/a/AbunaAcolyte.java @@ -24,7 +24,7 @@ import mage.target.common.TargetCreaturePermanent; */ public final class AbunaAcolyte extends CardImpl { - final static FilterCreaturePermanent filter = new FilterCreaturePermanent("artifact creature"); + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("artifact creature"); static { filter.add(new CardTypePredicate(CardType.ARTIFACT)); @@ -45,7 +45,7 @@ public final class AbunaAcolyte extends CardImpl { this.addAbility(ability2); } - public AbunaAcolyte(final AbunaAcolyte card) { + private AbunaAcolyte(final AbunaAcolyte card) { super(card); } diff --git a/Mage.Sets/src/mage/cards/a/AccursedHorde.java b/Mage.Sets/src/mage/cards/a/AccursedHorde.java index ec9d3d27b6..29c99ad77b 100644 --- a/Mage.Sets/src/mage/cards/a/AccursedHorde.java +++ b/Mage.Sets/src/mage/cards/a/AccursedHorde.java @@ -24,7 +24,7 @@ import mage.target.common.TargetAttackingCreature; */ public final class AccursedHorde extends CardImpl { - private final static FilterAttackingCreature filter = new FilterAttackingCreature("attacking Zombie"); + private static final FilterAttackingCreature filter = new FilterAttackingCreature("attacking Zombie"); static { filter.add(new SubtypePredicate(SubType.ZOMBIE)); @@ -43,7 +43,7 @@ public final class AccursedHorde extends CardImpl { this.addAbility(ability); } - public AccursedHorde(final AccursedHorde card) { + private AccursedHorde(final AccursedHorde card) { super(card); } diff --git a/Mage.Sets/src/mage/cards/a/AdmiralBeckettBrass.java b/Mage.Sets/src/mage/cards/a/AdmiralBeckettBrass.java index 18448c3cd8..0d675b09f2 100644 --- a/Mage.Sets/src/mage/cards/a/AdmiralBeckettBrass.java +++ b/Mage.Sets/src/mage/cards/a/AdmiralBeckettBrass.java @@ -74,7 +74,7 @@ class DamagedByPiratesWatcher extends Watcher { super(DamagedByPiratesWatcher.class.getSimpleName(), WatcherScope.GAME); } - public DamagedByPiratesWatcher(final DamagedByPiratesWatcher watcher) { + private DamagedByPiratesWatcher(final DamagedByPiratesWatcher watcher) { super(watcher); for (UUID playerId : watcher.damageSourceIds.keySet()) { Set creatures = new HashSet<>(); @@ -106,7 +106,7 @@ class DamagedByPiratesWatcher extends Watcher { } } - public boolean damagedByEnoughPirates(UUID sourceId, Game game) { + public boolean damagedByEnoughPirates(UUID sourceId) { return damageSourceIds.keySet().contains(sourceId) && damageSourceIds.get(sourceId).size() > 2; } @@ -119,14 +119,11 @@ class DamagedByPiratesWatcher extends Watcher { class ControllerDealtDamageByPiratesPredicate implements Predicate { - public ControllerDealtDamageByPiratesPredicate() { - } - @Override public boolean apply(Permanent input, Game game) { DamagedByPiratesWatcher watcher = game.getState().getWatcher(DamagedByPiratesWatcher.class); if (watcher != null) { - return watcher.damagedByEnoughPirates(input.getControllerId(), game); + return watcher.damagedByEnoughPirates(input.getControllerId()); } return false; } diff --git a/Mage.Sets/src/mage/cards/a/AeronautTinkerer.java b/Mage.Sets/src/mage/cards/a/AeronautTinkerer.java index a532d44cd6..769b373b33 100644 --- a/Mage.Sets/src/mage/cards/a/AeronautTinkerer.java +++ b/Mage.Sets/src/mage/cards/a/AeronautTinkerer.java @@ -22,7 +22,7 @@ import mage.filter.common.FilterControlledArtifactPermanent; */ public final class AeronautTinkerer extends CardImpl { - final static private String rule = "{this} has flying as long as you control an artifact"; + private static final String rule = "{this} has flying as long as you control an artifact"; public AeronautTinkerer(UUID ownerId, CardSetInfo setInfo) { super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{U}"); @@ -38,7 +38,7 @@ public final class AeronautTinkerer extends CardImpl { } - public AeronautTinkerer(final AeronautTinkerer card) { + private AeronautTinkerer(final AeronautTinkerer card) { super(card); } diff --git a/Mage.Sets/src/mage/cards/a/AetherMeltdown.java b/Mage.Sets/src/mage/cards/a/AetherMeltdown.java index c206ad09e5..999dfe2ab6 100644 --- a/Mage.Sets/src/mage/cards/a/AetherMeltdown.java +++ b/Mage.Sets/src/mage/cards/a/AetherMeltdown.java @@ -26,7 +26,7 @@ import mage.target.TargetPermanent; */ public final class AetherMeltdown extends CardImpl { - private final static FilterPermanent filter = new FilterPermanent("creature or vehicle"); + private static final FilterPermanent filter = new FilterPermanent("creature or vehicle"); static { filter.add(Predicates.or(new CardTypePredicate(CardType.CREATURE), new SubtypePredicate(SubType.VEHICLE))); @@ -53,7 +53,7 @@ public final class AetherMeltdown extends CardImpl { this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect)); } - public AetherMeltdown(final AetherMeltdown card) { + private AetherMeltdown(final AetherMeltdown card) { super(card); } diff --git a/Mage.Sets/src/mage/cards/a/AetherStorm.java b/Mage.Sets/src/mage/cards/a/AetherStorm.java index caf533324a..a2298fa7be 100644 --- a/Mage.Sets/src/mage/cards/a/AetherStorm.java +++ b/Mage.Sets/src/mage/cards/a/AetherStorm.java @@ -36,7 +36,7 @@ public final class AetherStorm extends CardImpl { this.addAbility(ability); } - public AetherStorm(final AetherStorm card) { + private AetherStorm(final AetherStorm card) { super(card); } @@ -53,7 +53,7 @@ class AetherStormReplacementEffect extends ContinuousRuleModifyingEffectImpl { staticText = "Creature spells can't be cast."; } - public AetherStormReplacementEffect(final AetherStormReplacementEffect effect) { + private AetherStormReplacementEffect(final AetherStormReplacementEffect effect) { super(effect); } @@ -75,10 +75,7 @@ class AetherStormReplacementEffect extends ContinuousRuleModifyingEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { Card card = game.getCard(event.getSourceId()); - if (card != null && card.isCreature()) { - return true; - } - return false; + return card != null && card.isCreature(); } } diff --git a/Mage.Sets/src/mage/cards/a/AjanisAid.java b/Mage.Sets/src/mage/cards/a/AjanisAid.java index 1bfe98285e..9728a402c3 100644 --- a/Mage.Sets/src/mage/cards/a/AjanisAid.java +++ b/Mage.Sets/src/mage/cards/a/AjanisAid.java @@ -23,7 +23,7 @@ import mage.filter.predicate.mageobject.NamePredicate; */ public final class AjanisAid extends CardImpl { - private final static FilterCard filter = new FilterCard("Ajani, Valiant Protector"); + private static final FilterCard filter = new FilterCard("Ajani, Valiant Protector"); static { filter.add(new NamePredicate("Ajani, Valiant Protector")); @@ -42,7 +42,7 @@ public final class AjanisAid extends CardImpl { this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new SacrificeSourceCost())); } - public AjanisAid(final AjanisAid card) { + private AjanisAid(final AjanisAid card) { super(card); } diff --git a/Mage.Sets/src/mage/cards/a/AllSunsDawn.java b/Mage.Sets/src/mage/cards/a/AllSunsDawn.java index 3278bd9a59..2a882a21f7 100644 --- a/Mage.Sets/src/mage/cards/a/AllSunsDawn.java +++ b/Mage.Sets/src/mage/cards/a/AllSunsDawn.java @@ -1,7 +1,6 @@ package mage.cards.a; -import java.util.UUID; import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; @@ -17,17 +16,18 @@ import mage.players.Player; import mage.target.Target; import mage.target.common.TargetCardInYourGraveyard; +import java.util.UUID; + /** - * * @author LevelX2 */ public final class AllSunsDawn extends CardImpl { - private final static FilterCard filterGreen = new FilterCard("green card from your graveyard"); - private final static FilterCard filterRed = new FilterCard("red card from your graveyard"); - private final static FilterCard filterBlue = new FilterCard("blue card from your graveyard"); - private final static FilterCard filterBlack = new FilterCard("black card from your graveyard"); - private final static FilterCard filterWhite = new FilterCard("white card from your graveyard"); + private static final FilterCard filterGreen = new FilterCard("green card from your graveyard"); + private static final FilterCard filterRed = new FilterCard("red card from your graveyard"); + private static final FilterCard filterBlue = new FilterCard("blue card from your graveyard"); + private static final FilterCard filterBlack = new FilterCard("black card from your graveyard"); + private static final FilterCard filterWhite = new FilterCard("white card from your graveyard"); static { filterGreen.add(new ColorPredicate(ObjectColor.GREEN)); @@ -38,7 +38,7 @@ public final class AllSunsDawn extends CardImpl { } public AllSunsDawn(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{4}{G}"); + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{4}{G}"); // For each color, return up to one target card of that color from your graveyard to your hand. this.getSpellAbility().addEffect(new AllSunsDawnEffect()); @@ -51,7 +51,7 @@ public final class AllSunsDawn extends CardImpl { this.getSpellAbility().addEffect(ExileSpellEffect.getInstance()); } - public AllSunsDawn(final AllSunsDawn card) { + private AllSunsDawn(final AllSunsDawn card) { super(card); } @@ -68,7 +68,7 @@ class AllSunsDawnEffect extends OneShotEffect { this.staticText = "For each color, return up to one target card of that color from your graveyard to your hand"; } - public AllSunsDawnEffect(final AllSunsDawnEffect effect) { + private AllSunsDawnEffect(final AllSunsDawnEffect effect) { super(effect); } @@ -89,8 +89,7 @@ class AllSunsDawnEffect extends OneShotEffect { cardsToHand.add(card); } } - controller.moveCards(cardsToHand, Zone.HAND, source, game); - return true; + return controller.moveCards(cardsToHand, Zone.HAND, source, game); } return false; } diff --git a/Mage.Sets/src/mage/cards/a/ArchiveTrap.java b/Mage.Sets/src/mage/cards/a/ArchiveTrap.java index 4320b92011..0be35df652 100644 --- a/Mage.Sets/src/mage/cards/a/ArchiveTrap.java +++ b/Mage.Sets/src/mage/cards/a/ArchiveTrap.java @@ -51,13 +51,13 @@ public final class ArchiveTrap extends CardImpl { class ArchiveTrapWatcher extends Watcher { - Set playerIds = new HashSet<>(); + private Set playerIds = new HashSet<>(); public ArchiveTrapWatcher() { super(ArchiveTrapWatcher.class.getSimpleName(), WatcherScope.GAME); } - public ArchiveTrapWatcher(final ArchiveTrapWatcher watcher) { + private ArchiveTrapWatcher(final ArchiveTrapWatcher watcher) { super(watcher); this.playerIds.addAll(watcher.playerIds); } diff --git a/Mage.Sets/src/mage/cards/a/AwakenTheErstwhile.java b/Mage.Sets/src/mage/cards/a/AwakenTheErstwhile.java index 75403136dc..13a4d8ad62 100644 --- a/Mage.Sets/src/mage/cards/a/AwakenTheErstwhile.java +++ b/Mage.Sets/src/mage/cards/a/AwakenTheErstwhile.java @@ -70,13 +70,13 @@ class AwakenTheErstwhileEffect extends OneShotEffect { } // create tokens - for (UUID playerId : cardsAmount.keySet()) { - Player player = game.getPlayer(playerId); - int tokensCount = cardsAmount.get(playerId); + cardsAmount.entrySet().forEach(discardedHand -> { + Player player = game.getPlayer(discardedHand.getKey()); + int tokensCount = discardedHand.getValue(); if (player != null && tokensCount > 0) { new ZombieToken().putOntoBattlefield(tokensCount, game, source.getSourceId(), player.getId()); } - } + }); return true; } diff --git a/Mage.Sets/src/mage/cards/b/BlazingEffigy.java b/Mage.Sets/src/mage/cards/b/BlazingEffigy.java index bc7d5800af..6ef735f7ee 100644 --- a/Mage.Sets/src/mage/cards/b/BlazingEffigy.java +++ b/Mage.Sets/src/mage/cards/b/BlazingEffigy.java @@ -55,7 +55,7 @@ enum BlazingEffigyCount implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { - BlazingEffigyWatcher watcher = (BlazingEffigyWatcher) game.getState().getWatchers().get(BlazingEffigyWatcher.class.getSimpleName()); + BlazingEffigyWatcher watcher = game.getState().getWatcher(BlazingEffigyWatcher.class); if (watcher == null) { return 3; } diff --git a/Mage.Sets/src/mage/cards/c/ConduitOfRuin.java b/Mage.Sets/src/mage/cards/c/ConduitOfRuin.java index c3bb6e1782..9709c1754c 100644 --- a/Mage.Sets/src/mage/cards/c/ConduitOfRuin.java +++ b/Mage.Sets/src/mage/cards/c/ConduitOfRuin.java @@ -71,8 +71,7 @@ public final class ConduitOfRuin extends CardImpl { class ConduitOfRuinWatcher extends Watcher { - Map playerCreatureSpells; - int spellCount = 0; + private Map playerCreatureSpells; public ConduitOfRuinWatcher() { super(ConduitOfRuinWatcher.class.getSimpleName(), WatcherScope.GAME); diff --git a/Mage.Sets/src/mage/cards/c/CustodiSoulcaller.java b/Mage.Sets/src/mage/cards/c/CustodiSoulcaller.java index 1f19992bec..95ec6d8866 100644 --- a/Mage.Sets/src/mage/cards/c/CustodiSoulcaller.java +++ b/Mage.Sets/src/mage/cards/c/CustodiSoulcaller.java @@ -69,7 +69,7 @@ enum CustodiSoulcallerAdjuster implements TargetAdjuster { @Override public void adjustTargets(Ability ability, Game game) { ability.getTargets().clear(); - CustodiSoulcallerWatcher watcher = (CustodiSoulcallerWatcher) game.getState().getWatchers().get(CustodiSoulcallerWatcher.class.getSimpleName()); + CustodiSoulcallerWatcher watcher = game.getState().getWatcher(CustodiSoulcallerWatcher.class); Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(ability.getSourceId()); if (watcher != null) { int xValue = watcher.getNumberOfAttackedPlayers(sourcePermanent.getControllerId()); diff --git a/Mage.Sets/src/mage/cards/f/FaithsReward.java b/Mage.Sets/src/mage/cards/f/FaithsReward.java index 1987daeffb..5c46a5e563 100644 --- a/Mage.Sets/src/mage/cards/f/FaithsReward.java +++ b/Mage.Sets/src/mage/cards/f/FaithsReward.java @@ -59,7 +59,7 @@ class FaithsRewardEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { FaithsRewardWatcher watcher = game.getState().getWatcher(FaithsRewardWatcher.class); if (watcher != null) { - for (UUID id : watcher.cards) { + for (UUID id : watcher.getCards()) { Card c = game.getCard(id); if (c != null && c.isOwnedBy(source.getControllerId()) && game.getState().getZone(id) == Zone.GRAVEYARD) { c.moveToZone(Zone.BATTLEFIELD, source.getSourceId(), game, false); @@ -77,7 +77,7 @@ class FaithsRewardEffect extends OneShotEffect { } class FaithsRewardWatcher extends Watcher { - List cards = new ArrayList<>(); + private List cards = new ArrayList<>(); public FaithsRewardWatcher() { super(FaithsRewardWatcher.class, WatcherScope.GAME); @@ -95,6 +95,10 @@ class FaithsRewardWatcher extends Watcher { } } + public List getCards(){ + return cards; + } + @Override public FaithsRewardWatcher copy() { return new FaithsRewardWatcher(this); diff --git a/Mage.Sets/src/mage/cards/g/GeneratorServant.java b/Mage.Sets/src/mage/cards/g/GeneratorServant.java index 9ecc3a190d..144f828056 100644 --- a/Mage.Sets/src/mage/cards/g/GeneratorServant.java +++ b/Mage.Sets/src/mage/cards/g/GeneratorServant.java @@ -48,7 +48,7 @@ public final class GeneratorServant extends CardImpl { this.addAbility(new SimpleStaticAbility(Zone.ALL, new GeneratorServantHasteEffect()), new GeneratorServantWatcher()); } - public GeneratorServant(final GeneratorServant card) { + private GeneratorServant(final GeneratorServant card) { super(card); } @@ -60,13 +60,13 @@ public final class GeneratorServant extends CardImpl { class GeneratorServantWatcher extends Watcher { - public List creatures = new ArrayList<>(); + private List creatures = new ArrayList<>(); public GeneratorServantWatcher() { super(GeneratorServantWatcher.class, WatcherScope.CARD); } - public GeneratorServantWatcher(final GeneratorServantWatcher watcher) { + private GeneratorServantWatcher(final GeneratorServantWatcher watcher) { super(watcher); this.creatures.addAll(watcher.creatures); } @@ -95,6 +95,10 @@ class GeneratorServantWatcher extends Watcher { creatures.clear(); } + public boolean creatureCastWithServantsMana(UUID permanentId){ + return creatures.contains(permanentId); + } + } class GeneratorServantHasteEffect extends ContinuousEffectImpl { @@ -117,7 +121,7 @@ class GeneratorServantHasteEffect extends ContinuousEffectImpl { GeneratorServantWatcher watcher = game.getState().getWatcher(GeneratorServantWatcher.class, source.getSourceId()); if (watcher != null) { for (Permanent perm : game.getBattlefield().getAllActivePermanents()) { - if (watcher.creatures.contains(perm.getId())) { + if (watcher.creatureCastWithServantsMana(perm.getId())) { perm.addAbility(HasteAbility.getInstance(), source.getSourceId(), game); } } diff --git a/Mage.Sets/src/mage/cards/g/GisaAndGeralf.java b/Mage.Sets/src/mage/cards/g/GisaAndGeralf.java index 78c9859449..9adc4c9268 100644 --- a/Mage.Sets/src/mage/cards/g/GisaAndGeralf.java +++ b/Mage.Sets/src/mage/cards/g/GisaAndGeralf.java @@ -130,7 +130,7 @@ class GisaAndGeralfCastFromGraveyardEffect extends AsThoughEffectImpl { class GisaAndGeralfWatcher extends Watcher { - boolean abilityUsed = false; + private boolean abilityUsed = false; GisaAndGeralfWatcher() { super("GisaAndGeralfWatcher", WatcherScope.CARD); diff --git a/Mage.Sets/src/mage/cards/g/GlyphOfDelusion.java b/Mage.Sets/src/mage/cards/g/GlyphOfDelusion.java index 01086867ac..f035da7779 100644 --- a/Mage.Sets/src/mage/cards/g/GlyphOfDelusion.java +++ b/Mage.Sets/src/mage/cards/g/GlyphOfDelusion.java @@ -84,7 +84,7 @@ class GlyphOfDelusionSecondTarget extends TargetPermanent { public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { Set possibleTargets = new HashSet<>(); if (firstTarget != null) { - BlockedAttackerWatcher watcher = (BlockedAttackerWatcher) game.getState().getWatchers().get(BlockedAttackerWatcher.class.getSimpleName()); + BlockedAttackerWatcher watcher = game.getState().getWatcher(BlockedAttackerWatcher.class); if (watcher != null) { MageObject targetSource = game.getObject(sourceId); if (targetSource != null) { diff --git a/Mage.Sets/src/mage/cards/g/GlyphOfReincarnation.java b/Mage.Sets/src/mage/cards/g/GlyphOfReincarnation.java index 94068e41ef..b422b7d662 100644 --- a/Mage.Sets/src/mage/cards/g/GlyphOfReincarnation.java +++ b/Mage.Sets/src/mage/cards/g/GlyphOfReincarnation.java @@ -86,7 +86,7 @@ class GlyphOfReincarnationEffect extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); Permanent targetWall = game.getPermanentOrLKIBattlefield(source.getFirstTarget()); if (controller != null && targetWall != null) { - BlockedAttackerWatcher watcher = (BlockedAttackerWatcher) game.getState().getWatchers().get(BlockedAttackerWatcher.class.getSimpleName()); + BlockedAttackerWatcher watcher = game.getState().getWatcher(BlockedAttackerWatcher.class); if (watcher != null) { Map destroyed = new HashMap<>(); for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) { diff --git a/Mage.Sets/src/mage/cards/i/IchneumonDruid.java b/Mage.Sets/src/mage/cards/i/IchneumonDruid.java index 04ed82b35c..bb0a6ec05f 100644 --- a/Mage.Sets/src/mage/cards/i/IchneumonDruid.java +++ b/Mage.Sets/src/mage/cards/i/IchneumonDruid.java @@ -74,7 +74,7 @@ class IchneumonDruidAbility extends TriggeredAbilityImpl { if (!event.getPlayerId().equals(controllerId)) { Spell spell = game.getStack().getSpell(event.getTargetId()); if (spell != null && spell.isInstant()) { - IchneumonDruidWatcher watcher = (IchneumonDruidWatcher) game.getState().getWatchers().get(IchneumonDruidWatcher.class.getSimpleName()); + IchneumonDruidWatcher watcher = game.getState().getWatcher(IchneumonDruidWatcher.class); if (watcher != null && watcher.moreThanTwoInstantsCast(event.getPlayerId(), game)) { for (Effect effect : getEffects()) { effect.setTargetPointer(new FixedTarget(event.getPlayerId())); diff --git a/Mage.Sets/src/mage/cards/m/MetamorphicAlteration.java b/Mage.Sets/src/mage/cards/m/MetamorphicAlteration.java index 07c2c8a20a..6daa9c7245 100644 --- a/Mage.Sets/src/mage/cards/m/MetamorphicAlteration.java +++ b/Mage.Sets/src/mage/cards/m/MetamorphicAlteration.java @@ -56,7 +56,7 @@ public final class MetamorphicAlteration extends CardImpl { class ChooseACreature extends OneShotEffect { - public static String INFO_KEY = "CHOSEN_CREATURE"; + public static final String INFO_KEY = "CHOSEN_CREATURE"; public ChooseACreature() { super(Outcome.Copy); diff --git a/Mage.Sets/src/mage/cards/o/OpalPalace.java b/Mage.Sets/src/mage/cards/o/OpalPalace.java index bfc47e573f..95f2eb2a79 100644 --- a/Mage.Sets/src/mage/cards/o/OpalPalace.java +++ b/Mage.Sets/src/mage/cards/o/OpalPalace.java @@ -63,7 +63,7 @@ public final class OpalPalace extends CardImpl { class OpalPalaceWatcher extends Watcher { - public List commanderId = new ArrayList<>(); + private List commanderId = new ArrayList<>(); private final String originalId; public OpalPalaceWatcher(String originalId) { @@ -71,12 +71,16 @@ class OpalPalaceWatcher extends Watcher { this.originalId = originalId; } - public OpalPalaceWatcher(final OpalPalaceWatcher watcher) { + private OpalPalaceWatcher(final OpalPalaceWatcher watcher) { super(watcher); this.commanderId.addAll(watcher.commanderId); this.originalId = watcher.originalId; } + public boolean manaUsedToCastCommander(UUID id){ + return commanderId.contains(id); + } + @Override public OpalPalaceWatcher copy() { return new OpalPalaceWatcher(this); @@ -119,7 +123,7 @@ class OpalPalaceEntersBattlefieldEffect extends ReplacementEffectImpl { staticText = "If you spend this mana to cast your commander, it enters the battlefield with a number of +1/+1 counters on it equal to the number of times it's been cast from the command zone this game"; } - public OpalPalaceEntersBattlefieldEffect(OpalPalaceEntersBattlefieldEffect effect) { + private OpalPalaceEntersBattlefieldEffect(OpalPalaceEntersBattlefieldEffect effect) { super(effect); } @@ -132,7 +136,7 @@ class OpalPalaceEntersBattlefieldEffect extends ReplacementEffectImpl { public boolean applies(GameEvent event, Ability source, Game game) { OpalPalaceWatcher watcher = game.getState().getWatcher(OpalPalaceWatcher.class, source.getSourceId()); return watcher != null - && watcher.commanderId.contains(event.getTargetId()); + && watcher.manaUsedToCastCommander(event.getTargetId()); } @Override diff --git a/Mage.Sets/src/mage/cards/q/Quicken.java b/Mage.Sets/src/mage/cards/q/Quicken.java index 5025cb4e9d..3e9964a01f 100644 --- a/Mage.Sets/src/mage/cards/q/Quicken.java +++ b/Mage.Sets/src/mage/cards/q/Quicken.java @@ -97,13 +97,13 @@ class QuickenAsThoughEffect extends AsThoughEffectImpl { class QuickenWatcher extends Watcher { - public List activeQuickenSpells = new ArrayList<>(); + private List activeQuickenSpells = new ArrayList<>(); public QuickenWatcher() { super(QuickenWatcher.class, WatcherScope.GAME); } - public QuickenWatcher(final QuickenWatcher watcher) { + private QuickenWatcher(final QuickenWatcher watcher) { super(watcher); } diff --git a/Mage.Sets/src/mage/cards/t/TimeToReflect.java b/Mage.Sets/src/mage/cards/t/TimeToReflect.java index 727e2fd5b9..ce2626dfdc 100644 --- a/Mage.Sets/src/mage/cards/t/TimeToReflect.java +++ b/Mage.Sets/src/mage/cards/t/TimeToReflect.java @@ -52,7 +52,7 @@ enum TimeToReflectAdjuster implements TargetAdjuster { public void adjustTargets(Ability ability, Game game) { List creaturesThatBlockedOrWereBlockedByAZombie = new ArrayList<>(); FilterCreaturePermanent filter = new FilterCreaturePermanent("creature that blocked or was blocked by a Zombie this turn.").copy(); - BlockedOrWasBlockedByAZombieWatcher watcher = (BlockedOrWasBlockedByAZombieWatcher) game.getState().getWatchers().get(BlockedOrWasBlockedByAZombieWatcher.class.getSimpleName()); + BlockedOrWasBlockedByAZombieWatcher watcher = game.getState().getWatcher(BlockedOrWasBlockedByAZombieWatcher.class); if (watcher != null) { for (MageObjectReference mor : watcher.getBlockedThisTurnCreatures()) { Permanent permanent = mor.getPermanent(game); diff --git a/Mage.Sets/src/mage/cards/t/TreasureNabber.java b/Mage.Sets/src/mage/cards/t/TreasureNabber.java index 9a62b20545..b851dbd574 100644 --- a/Mage.Sets/src/mage/cards/t/TreasureNabber.java +++ b/Mage.Sets/src/mage/cards/t/TreasureNabber.java @@ -92,7 +92,6 @@ class TreasureNabberAbility extends TriggeredAbilityImpl { class TreasureNabberEffect extends ContinuousEffectImpl { protected FixedTargets fixedTargets; - protected int startingTurn; TreasureNabberEffect() { super(Duration.Custom, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl); diff --git a/Mage.Sets/src/mage/cards/v/VizierOfDeferment.java b/Mage.Sets/src/mage/cards/v/VizierOfDeferment.java index 6e24c93d23..e7b275a073 100644 --- a/Mage.Sets/src/mage/cards/v/VizierOfDeferment.java +++ b/Mage.Sets/src/mage/cards/v/VizierOfDeferment.java @@ -76,8 +76,8 @@ class VizierOfDefermentEffect extends OneShotEffect { Permanent permanent = game.getPermanent(source.getFirstTarget()); Player controller = game.getPlayer(source.getControllerId()); Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); - AttackedThisTurnWatcher watcherAttacked = (AttackedThisTurnWatcher) game.getState().getWatchers().get(AttackedThisTurnWatcher.class.getSimpleName()); - BlockedThisTurnWatcher watcherBlocked = (BlockedThisTurnWatcher) game.getState().getWatchers().get(BlockedThisTurnWatcher.class.getSimpleName()); + AttackedThisTurnWatcher watcherAttacked = game.getState().getWatcher(AttackedThisTurnWatcher.class); + BlockedThisTurnWatcher watcherBlocked = game.getState().getWatcher(BlockedThisTurnWatcher.class); boolean attackedOrBlocked = false; if (watcherAttacked != null && watcherAttacked.checkIfAttacked(permanent, game)) { attackedOrBlocked = true; diff --git a/Mage/src/main/java/mage/game/GameState.java b/Mage/src/main/java/mage/game/GameState.java index 3caa16a21a..fb7f030e74 100644 --- a/Mage/src/main/java/mage/game/GameState.java +++ b/Mage/src/main/java/mage/game/GameState.java @@ -531,11 +531,6 @@ public class GameState implements Serializable, Copyable { return this.turnMods; } - @Deprecated - public Watchers getWatchers() { - return this.watchers; - } - public T getWatcher(Class watcherClass) { return watcherClass.cast(watchers.get(watcherClass.getSimpleName())); } diff --git a/Mage/src/main/java/mage/game/GameTinyLeadersImpl.java b/Mage/src/main/java/mage/game/GameTinyLeadersImpl.java index 768fe8efd8..eecbddd5f1 100644 --- a/Mage/src/main/java/mage/game/GameTinyLeadersImpl.java +++ b/Mage/src/main/java/mage/game/GameTinyLeadersImpl.java @@ -60,7 +60,7 @@ public abstract class GameTinyLeadersImpl extends GameImpl { // ability.addEffect(new CommanderManaReplacementEffect(player.getId(), CardUtil.getColorIdentity(commander))); getState().setValue(commander.getId() + "_castCount", 0); CommanderInfoWatcher watcher = new CommanderInfoWatcher(commander.getId(), false); - getState().getWatchers().add(watcher); + getState().addWatcher(watcher); watcher.addCardInfoToCommander(this); } else { throw new UnknownError("Commander card could not be created. Name: [" + player.getMatchPlayer().getDeck().getName() + ']');