From 85e65c8f44af0d5d9af5db08bc09fbbda00ce67c Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Wed, 8 Jan 2020 05:18:21 +0400 Subject: [PATCH] Code cleanup --- .../src/main/java/mage/server/User.java | 33 ++++++------ .../src/mage/cards/a/AncestralMemories.java | 54 ++----------------- .../src/mage/cards/t/TreetopVillage.java | 17 +++--- .../java/mage/verify/VerifyCardDataTest.java | 2 +- .../effects/ContinuousEffectImpl.java | 2 +- .../effects/common/ChooseACardNameEffect.java | 1 - .../LookAtTopCardOfLibraryAnyTimeEffect.java | 2 +- .../PlayWithTheTopCardRevealedEffect.java | 4 +- Mage/src/main/java/mage/players/Player.java | 4 ++ .../mage/watchers/common/MiracleWatcher.java | 1 - 10 files changed, 42 insertions(+), 78 deletions(-) diff --git a/Mage.Server/src/main/java/mage/server/User.java b/Mage.Server/src/main/java/mage/server/User.java index 930133aa73..ec940a2d2b 100644 --- a/Mage.Server/src/main/java/mage/server/User.java +++ b/Mage.Server/src/main/java/mage/server/User.java @@ -1,10 +1,5 @@ - package mage.server; -import java.util.*; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.TimeUnit; import mage.cards.decks.Deck; import mage.constants.ManaType; import mage.constants.TableState; @@ -29,6 +24,11 @@ import mage.server.util.SystemUtil; import mage.view.TableClientMessage; import org.apache.log4j.Logger; +import java.util.*; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; + /** * @author BetaSteward_at_googlemail.com */ @@ -180,7 +180,7 @@ public class User { public void lostConnection() { // Because watched games don't get restored after reconnection call stop watching - for (Iterator iterator = watchedGames.iterator(); iterator.hasNext();) { + for (Iterator iterator = watchedGames.iterator(); iterator.hasNext(); ) { UUID gameId = iterator.next(); GameManager.instance.stopWatching(gameId, userId); iterator.remove(); @@ -215,10 +215,10 @@ public class User { int minutes = (int) SystemUtil.getDateDiff(connectionTime, new Date(), TimeUnit.SECONDS) / 60; int hours = 0; if (minutes > 59) { - hours = (int) minutes / 60; + hours = minutes / 60; minutes = minutes - (hours * 60); } - return Integer.toString(hours) + ":" + (minutes > 9 ? Integer.toString(minutes) : '0' + Integer.toString(minutes)); + return hours + ":" + (minutes > 9 ? Integer.toString(minutes) : '0' + Integer.toString(minutes)); } public void fireCallback(final ClientCallback call) { @@ -329,10 +329,11 @@ public class User { private void reconnect() { logger.trace(userName + " started reconnect"); + //lastActivity = new Date(); // ??? comment to test can't reconnect to game on disconnect for (Entry entry : tables.entrySet()) { ccJoinedTable(entry.getValue().getRoomId(), entry.getValue().getId(), entry.getValue().isTournament()); } - for (Iterator> iterator = userTournaments.entrySet().iterator(); iterator.hasNext();) { + for (Iterator> iterator = userTournaments.entrySet().iterator(); iterator.hasNext(); ) { Entry next = iterator.next(); Optional tournamentController = TournamentManager.instance.getTournamentController(next.getValue()); if (tournamentController.isPresent()) { @@ -442,7 +443,7 @@ public class User { } gameSessions.clear(); logger.trace("REMOVE " + userName + " watched Games " + watchedGames.size()); - for (Iterator it = watchedGames.iterator(); it.hasNext();) { // Iterator to prevent ConcurrentModificationException + for (Iterator it = watchedGames.iterator(); it.hasNext(); ) { // Iterator to prevent ConcurrentModificationException UUID gameId = it.next(); GameManager.instance.stopWatching(gameId, userId); } @@ -658,13 +659,13 @@ public class User { builder.append(proto.getMatches()); List quit = new ArrayList<>(); if (proto.getMatchesIdleTimeout() > 0) { - quit.add("I:" + Integer.toString(proto.getMatchesIdleTimeout())); + quit.add("I:" + proto.getMatchesIdleTimeout()); } if (proto.getMatchesTimerTimeout() > 0) { - quit.add("T:" + Integer.toString(proto.getMatchesTimerTimeout())); + quit.add("T:" + proto.getMatchesTimerTimeout()); } if (proto.getMatchesQuit() > 0) { - quit.add("Q:" + Integer.toString(proto.getMatchesQuit())); + quit.add("Q:" + proto.getMatchesQuit()); } if (!quit.isEmpty()) { builder.append(" ("); @@ -690,13 +691,13 @@ public class User { builder.append(proto.getTourneys()); List quit = new ArrayList<>(); if (proto.getTourneysQuitDuringDrafting() > 0) { - quit.add("D:" + Integer.toString(proto.getTourneysQuitDuringDrafting())); + quit.add("D:" + proto.getTourneysQuitDuringDrafting()); } if (proto.getTourneysQuitDuringConstruction() > 0) { - quit.add("C:" + Integer.toString(proto.getTourneysQuitDuringConstruction())); + quit.add("C:" + proto.getTourneysQuitDuringConstruction()); } if (proto.getTourneysQuitDuringRound() > 0) { - quit.add("R:" + Integer.toString(proto.getTourneysQuitDuringRound())); + quit.add("R:" + proto.getTourneysQuitDuringRound()); } if (!quit.isEmpty()) { builder.append(" ("); diff --git a/Mage.Sets/src/mage/cards/a/AncestralMemories.java b/Mage.Sets/src/mage/cards/a/AncestralMemories.java index b7fb61cb3b..28cca50253 100644 --- a/Mage.Sets/src/mage/cards/a/AncestralMemories.java +++ b/Mage.Sets/src/mage/cards/a/AncestralMemories.java @@ -1,23 +1,16 @@ - package mage.cards.a; -import java.util.UUID; -import mage.abilities.Ability; import mage.abilities.dynamicvalue.common.StaticValue; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.LookLibraryAndPickControllerEffect; -import mage.cards.*; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.Zone; -import mage.filter.FilterCard; import mage.filter.StaticFilters; -import mage.game.Game; -import mage.players.Player; -import mage.target.TargetCard; + +import java.util.UUID; /** - * * @author Quercitron */ public final class AncestralMemories extends CardImpl { @@ -38,41 +31,4 @@ public final class AncestralMemories extends CardImpl { public AncestralMemories copy() { return new AncestralMemories(this); } -} - -class AncestralMemoriesEffect extends OneShotEffect { - - public AncestralMemoriesEffect() { - super(Outcome.DrawCard); - this.staticText = "Look at the top seven cards of your library. Put two of them into your hand and the rest into your graveyard"; - } - - public AncestralMemoriesEffect(final AncestralMemoriesEffect effect) { - super(effect); - } - - @Override - public AncestralMemoriesEffect copy() { - return new AncestralMemoriesEffect(this); - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 7)); - if (!cards.isEmpty()) { - controller.lookAtCards(source, null, cards, game); - TargetCard target = new TargetCard(Math.min(2, cards.size()), Zone.LIBRARY, new FilterCard("two cards to put in your hand")); - if (controller.choose(Outcome.DrawCard, cards, target, game)) { - Cards toHand = new CardsImpl(target.getTargets()); - controller.moveCards(cards, Zone.HAND, source, game); - cards.removeAll(toHand); - } - controller.moveCards(cards, Zone.GRAVEYARD, source, game); - } - return true; - } - return false; - } -} +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/cards/t/TreetopVillage.java b/Mage.Sets/src/mage/cards/t/TreetopVillage.java index e1a8b10a14..6ba058a4b2 100644 --- a/Mage.Sets/src/mage/cards/t/TreetopVillage.java +++ b/Mage.Sets/src/mage/cards/t/TreetopVillage.java @@ -1,7 +1,5 @@ - package mage.cards.t; -import java.util.UUID; import mage.MageInt; import mage.abilities.common.EntersBattlefieldTappedAbility; import mage.abilities.common.SimpleActivatedAbility; @@ -12,22 +10,28 @@ import mage.abilities.mana.GreenManaAbility; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.SubType; import mage.constants.Duration; +import mage.constants.SubType; import mage.constants.Zone; import mage.game.permanent.token.TokenImpl; -import mage.game.permanent.token.Token; + +import java.util.UUID; /** - * * @author Loki */ public final class TreetopVillage extends CardImpl { public TreetopVillage(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.LAND},""); + super(ownerId, setInfo, new CardType[]{CardType.LAND}, ""); + + // Treetop Village enters the battlefield tapped. this.addAbility(new EntersBattlefieldTappedAbility()); + + // {T}: Add {G}. this.addAbility(new GreenManaAbility()); + + // {1}{G}: Treetop Village becomes a 3/3 green Ape creature with trample until end of turn. It’s still a land. (It can deal excess combat damage to the player or planeswalker it’s attacking.) this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new BecomesCreatureSourceEffect(new ApeToken(), "land", Duration.EndOfTurn), new ManaCostsImpl("{1}{G}"))); } @@ -51,6 +55,7 @@ class ApeToken extends TokenImpl { toughness = new MageInt(3); this.addAbility(TrampleAbility.getInstance()); } + public ApeToken(final ApeToken token) { super(token); } diff --git a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java index a8e8bfbee8..e476ee281d 100644 --- a/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java +++ b/Mage.Verify/src/test/java/mage/verify/VerifyCardDataTest.java @@ -250,7 +250,7 @@ public class VerifyCardDataTest { cardsList.forEach((cardName, amount) -> { if (amount != 2) { - String error = "Error: found non duplicated rare card - " + String error = "Error: found non duplicated rare card -" + " set (" + set.getCode() + " - " + set.getName() + ")" + " card (" + cardName + ")"; doubleErrors.add(error); diff --git a/Mage/src/main/java/mage/abilities/effects/ContinuousEffectImpl.java b/Mage/src/main/java/mage/abilities/effects/ContinuousEffectImpl.java index 425aee2c12..7e1cfad748 100644 --- a/Mage/src/main/java/mage/abilities/effects/ContinuousEffectImpl.java +++ b/Mage/src/main/java/mage/abilities/effects/ContinuousEffectImpl.java @@ -398,7 +398,7 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu } } - public boolean isCanLookAtNextTopLibraryCard(Game game) { + public boolean canLookAtNextTopLibraryCard(Game game) { // If the top card of your library changes while you’re casting a spell, playing a land, or activating an ability, // you can’t look at the new top card until you finish doing so. This means that if you cast the top card of // your library, you can’t look at the next one until you’re done paying for that spell. (2019-05-03) diff --git a/Mage/src/main/java/mage/abilities/effects/common/ChooseACardNameEffect.java b/Mage/src/main/java/mage/abilities/effects/common/ChooseACardNameEffect.java index 79aea129af..c888d2703f 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/ChooseACardNameEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/ChooseACardNameEffect.java @@ -20,7 +20,6 @@ public class ChooseACardNameEffect extends OneShotEffect { public static final String INFO_KEY = "NAMED_CARD"; public enum TypeOfName { - ALL, NOT_BASIC_LAND_NAME, NONBASIC_LAND_NAME, diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/LookAtTopCardOfLibraryAnyTimeEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/LookAtTopCardOfLibraryAnyTimeEffect.java index 5749b100b1..0913b434b9 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/LookAtTopCardOfLibraryAnyTimeEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/LookAtTopCardOfLibraryAnyTimeEffect.java @@ -39,7 +39,7 @@ public class LookAtTopCardOfLibraryAnyTimeEffect extends ContinuousEffectImpl { if (obj == null) { return false; } - if (!isCanLookAtNextTopLibraryCard(game)) { + if (!canLookAtNextTopLibraryCard(game)) { return false; } controller.lookAtCards("Top card of " + obj.getIdName() + " controller's library", topCard, game); diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/PlayWithTheTopCardRevealedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/PlayWithTheTopCardRevealedEffect.java index a826bc0cd1..e813f875fa 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/PlayWithTheTopCardRevealedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/PlayWithTheTopCardRevealedEffect.java @@ -44,11 +44,11 @@ public class PlayWithTheTopCardRevealedEffect extends ContinuousEffectImpl { if (allPlayers) { for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); - if (player != null && isCanLookAtNextTopLibraryCard(game)) { + if (player != null && canLookAtNextTopLibraryCard(game)) { player.setTopCardRevealed(true); } } - } else if (isCanLookAtNextTopLibraryCard(game)) { + } else if (canLookAtNextTopLibraryCard(game)) { controller.setTopCardRevealed(true); } return true; diff --git a/Mage/src/main/java/mage/players/Player.java b/Mage/src/main/java/mage/players/Player.java index 253c3ebb42..18595863e2 100644 --- a/Mage/src/main/java/mage/players/Player.java +++ b/Mage/src/main/java/mage/players/Player.java @@ -456,6 +456,8 @@ public interface Player extends MageItem, Copyable { /** * Adds the cards to the reveal window and adds the source object's id name * to the title bar of the revealed cards window + *

+ * Warning, if you use it from continuous effect, then check with extra call isCanLookAtNextTopLibraryCard * * @param source * @param name @@ -472,6 +474,8 @@ public interface Player extends MageItem, Copyable { /** * Adds the cards to the look window and adds the source object's id name to * the title bar of the lookedAt window + *

+ * Warning, if you use it from continuous effect, then check with extra call isCanLookAtNextTopLibraryCard * * @param source * @param name diff --git a/Mage/src/main/java/mage/watchers/common/MiracleWatcher.java b/Mage/src/main/java/mage/watchers/common/MiracleWatcher.java index 69aa90939c..30202fc773 100644 --- a/Mage/src/main/java/mage/watchers/common/MiracleWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/MiracleWatcher.java @@ -14,7 +14,6 @@ import mage.watchers.Watcher; import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; import java.util.UUID; /**