diff --git a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java index 55ffe7c044..223a3d6ffa 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java @@ -250,12 +250,13 @@ public class TablesPanel extends javax.swing.JPanel { } public void showTables(UUID roomId) { - this.roomId = roomId; session = MageFrame.getSession(); + UUID chatRoomId = null; if (session != null) { btnQuickStart.setVisible(session.isTestMode()); gameChooser.init(session); + chatRoomId = session.getRoomChatId(roomId); } if (newTableDialog == null) { newTableDialog = new NewTableDialog(); @@ -269,14 +270,12 @@ public class TablesPanel extends javax.swing.JPanel { joinTableDialog = new JoinTableDialog(); MageFrame.getDesktop().add(joinTableDialog, JLayeredPane.MODAL_LAYER); } - UUID chatRoomId = session.getRoomChatId(roomId); if (chatRoomId != null) { this.chatPanel.connect(chatRoomId); startTasks(); this.setVisible(true); this.repaint(); - } - else { + } else { hideTables(); } diff --git a/Mage.Plugins/Mage.Counter.Plugin/src/main/java/org/mage/plugins/counter/CounterPluginImpl.java b/Mage.Plugins/Mage.Counter.Plugin/src/main/java/org/mage/plugins/counter/CounterPluginImpl.java index 0833e9fb21..be90865ee9 100644 --- a/Mage.Plugins/Mage.Counter.Plugin/src/main/java/org/mage/plugins/counter/CounterPluginImpl.java +++ b/Mage.Plugins/Mage.Counter.Plugin/src/main/java/org/mage/plugins/counter/CounterPluginImpl.java @@ -63,6 +63,7 @@ public class CounterPluginImpl implements CounterPlugin { log.info(plugin.toString() + " has been loaded."); } + @Override public String toString() { return "[Game counter plugin, version 0.1]"; } @@ -78,7 +79,7 @@ public class CounterPluginImpl implements CounterPlugin { try { ois = new ObjectInputStream(new FileInputStream(data)); Object o = ois.readObject(); - CounterBean c = null; + CounterBean c; if (o instanceof CounterBean) { c = (CounterBean)o; prev = c.getGamesPlayed(); @@ -129,7 +130,7 @@ public class CounterPluginImpl implements CounterPlugin { c = (CounterBean)o; } ois.close(); - return c.getGamesPlayed(); + return c == null ? 0 : c.getGamesPlayed(); } } catch (EOFException e) { return 0; diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java index b120daf40a..8b77b223b8 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/ComputerPlayer6.java @@ -137,9 +137,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements if (game.getActivePlayerId().equals(playerId)) { if (logger.isInfoEnabled()) { printOutState(game, playerId); - Iterator it = game.getOpponents(playerId).iterator(); - while (it.hasNext()) { - UUID opponentId = (UUID) it.next(); + for (UUID opponentId : game.getOpponents(playerId)) { printOutState(game, opponentId); } } @@ -395,7 +393,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements for (UUID targetId : target.possibleTargets(ability.getSourceId(), ability.getControllerId(), game)) { Game sim = game.copy(); StackAbility newAbility = (StackAbility) ability.copy(); - SearchEffect newEffect = getSearchEffect((StackAbility) newAbility); + SearchEffect newEffect = getSearchEffect(newAbility); newEffect.getTarget().addTarget(targetId, newAbility, sim); sim.getStack().push(newAbility); SimulationNode2 newNode = new SimulationNode2(node, sim, depth, ability.getControllerId()); @@ -1298,7 +1296,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements return false; } - protected void getSuggestedActions() { + protected final void getSuggestedActions() { try { File file = new File(FILE_WITH_INSTRUCTIONS); if (file.exists()) { @@ -1323,7 +1321,7 @@ public class ComputerPlayer6 extends ComputerPlayer implements @Override public void addAction(String action) { System.out.println("adding to suggested actions: " + action); - if (action != null && action.startsWith("cast:") || action.startsWith("play:")) { + if (action != null && (action.startsWith("cast:") || action.startsWith("play:"))) { suggested.add(action.substring(5, action.length())); } } diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index 818985ffb1..3f85df795f 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -1036,8 +1036,7 @@ public class ComputerPlayer> extends PlayerImpl i } }); List result = new ArrayList(); - for (Iterator it = list.iterator(); it.hasNext();) { - Entry entry = (Entry)it.next(); + for (Entry entry : list) { result.add(entry.getKey()); } return result; @@ -1086,9 +1085,7 @@ public class ComputerPlayer> extends PlayerImpl i } if (!choice.isChosen()) { int choiceIdx = (int) (Math.random()*choice.getChoices().size()+1); - Iterator iterator = choice.getChoices().iterator(); - while (iterator.hasNext()) { - String next = (String) iterator.next(); + for (String next : choice.getChoices()) { if (--choiceIdx > 0) { continue; } @@ -1159,7 +1156,7 @@ public class ComputerPlayer> extends PlayerImpl i @Override public boolean chooseTarget(Outcome outcome, Cards cards, TargetCard target, Ability source, Game game) { log.debug("chooseTarget"); - if (cards != null && cards.isEmpty()) { + if (cards == null || cards.isEmpty()) { if (!target.isRequired()) { return false; } @@ -1183,7 +1180,7 @@ public class ComputerPlayer> extends PlayerImpl i @Override public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) { log.debug("choose 2"); - if (cards != null && cards.isEmpty()) { + if (cards == null || cards.isEmpty()) { if (!target.isRequired()) { return false; } @@ -1585,9 +1582,9 @@ public class ComputerPlayer> extends PlayerImpl i if (o1.score.equals(o2.score)) { Integer i1 = RateCard.getColorManaCount(o1.card); Integer i2 = RateCard.getColorManaCount(o2.card); - return -i1.compareTo(i2); + return i2.compareTo(i1); } - return -o1.score.compareTo(o2.score); + return o2.score.compareTo(o1.score); } }); Set chosenSymbols = new HashSet(); diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/ShapeAnew.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/ShapeAnew.java index 0ad082aca8..07df0a3284 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/ShapeAnew.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/ShapeAnew.java @@ -111,7 +111,9 @@ public class ShapeAnew extends CardImpl { nonArtifactCards.add(card); } player.revealCards("Shape Anew", revealed, game); - artifactCard.putOntoBattlefield(game, Constants.Zone.LIBRARY, source.getId(), player.getId()); + if (artifactCard != null) { + artifactCard.putOntoBattlefield(game, Constants.Zone.LIBRARY, source.getId(), player.getId()); + } player.getLibrary().addAll(nonArtifactCards.getCards(game), game); player.shuffleLibrary(game); return true; diff --git a/Mage/src/mage/abilities/effects/common/search/SearchTargetGraveyardHandLibraryForCardNameAndExileEffect.java b/Mage/src/mage/abilities/effects/common/search/SearchTargetGraveyardHandLibraryForCardNameAndExileEffect.java index 6b4d2677b4..e2ee6af1a6 100644 --- a/Mage/src/mage/abilities/effects/common/search/SearchTargetGraveyardHandLibraryForCardNameAndExileEffect.java +++ b/Mage/src/mage/abilities/effects/common/search/SearchTargetGraveyardHandLibraryForCardNameAndExileEffect.java @@ -125,9 +125,9 @@ public abstract class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect } // cards in Library - Cards cardsInLibrary = new CardsImpl(Zone.LIBRARY); - cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game)); - cardsCount = (cardName.isEmpty() ? 0 :cardsInLibrary.count(filter, game)); + Cards cardsInLibrary = new CardsImpl(Zone.LIBRARY); + cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game)); + cardsCount = (cardName.isEmpty() ? 0 : cardsInLibrary.count(filter, game)); if (cardsCount > 0) { filter.setMessage("card named " + cardName + " in the library of " + targetPlayer.getName()); TargetCardInLibrary target = new TargetCardInLibrary(0, cardsCount, filter); @@ -143,9 +143,9 @@ public abstract class SearchTargetGraveyardHandLibraryForCardNameAndExileEffect } else { player.lookAtCards(targetPlayer.getName() + " library", cardsInLibrary, game); } - } - targetPlayer.shuffleLibrary(game); + targetPlayer.shuffleLibrary(game); + } return true; } diff --git a/Mage/src/mage/game/turn/Phase.java b/Mage/src/mage/game/turn/Phase.java index 345ca4408f..eb5093907f 100644 --- a/Mage/src/mage/game/turn/Phase.java +++ b/Mage/src/mage/game/turn/Phase.java @@ -65,8 +65,9 @@ public abstract class Phase> implements Serializable { this.preEvent = phase.preEvent; this.postEvent = phase.postEvent; this.activePlayerId = phase.activePlayerId; - if (phase.currentStep != null) + if (phase.currentStep != null) { this.currentStep = phase.currentStep.copy(); + } this.count = phase.count; for (Step step: phase.steps) { this.steps.add(step.copy()); @@ -94,24 +95,29 @@ public abstract class Phase> implements Serializable { } public boolean play(Game game, UUID activePlayerId) { - if (game.isPaused() || game.isGameOver()) + if (game.isPaused() || game.isGameOver()) { return false; + } this.activePlayerId = activePlayerId; if (beginPhase(game, activePlayerId)) { for (Step step: steps) { - if (game.isPaused() || game.isGameOver()) + if (game.isPaused() || game.isGameOver()) { return false; + } currentStep = step; - if (!game.isSimulation() && checkStopOnStepOption(game)) + if (!game.isSimulation() && checkStopOnStepOption(game)) { return false; - if (!game.getState().getTurnMods().skipStep(activePlayerId, getStep().getType())) + } + if (!game.getState().getTurnMods().skipStep(activePlayerId, getStep().getType())) { playStep(game); + } } - if (game.isPaused() || game.isGameOver()) + if (game.isPaused() || game.isGameOver()) { return false; + } count++; endPhase(game, activePlayerId); return true; @@ -130,8 +136,9 @@ public abstract class Phase> implements Serializable { } public boolean resumePlay(Game game, PhaseStep stepType, boolean wasPaused) { - if (game.isPaused() || game.isGameOver()) + if (game.isPaused() || game.isGameOver()) { return false; + } this.activePlayerId = game.getActivePlayerId(); Iterator it = steps.iterator(); @@ -143,15 +150,18 @@ public abstract class Phase> implements Serializable { resumeStep(game, wasPaused); while (it.hasNext()) { step = it.next(); - if (game.isPaused() || game.isGameOver()) + if (game.isPaused() || game.isGameOver()) { return false; + } currentStep = step; - if (!game.getState().getTurnMods().skipStep(activePlayerId, currentStep.getType())) + if (!game.getState().getTurnMods().skipStep(activePlayerId, currentStep.getType())) { playStep(game); + } } - if (game.isPaused() || game.isGameOver()) + if (game.isPaused() || game.isGameOver()) { return false; + } count++; endPhase(game, activePlayerId); return true; @@ -184,17 +194,21 @@ public abstract class Phase> implements Serializable { protected void playStep(Game game) { if (!currentStep.skipStep(game, activePlayerId)) { prePriority(game, activePlayerId); - if (!game.isPaused() && !game.isGameOver()) + if (!game.isPaused() && !game.isGameOver()) { currentStep.priority(game, activePlayerId, false); - if (!game.isPaused() && !game.isGameOver()) + } + if (!game.isPaused() && !game.isGameOver()) { postPriority(game, activePlayerId); + } } } protected void resumeStep(Game game, boolean wasPaused) { boolean resuming = true; - if (currentStep == null || currentStep.getStepPart() == null) + if (currentStep == null || currentStep.getStepPart() == null) { game.end(); + return; + } switch (currentStep.getStepPart()) { case PRE: if (wasPaused) { @@ -205,19 +219,22 @@ public abstract class Phase> implements Serializable { prePriority(game, activePlayerId); } case PRIORITY: - if (!game.isPaused() && !game.isGameOver()) + if (!game.isPaused() && !game.isGameOver()) { currentStep.priority(game, activePlayerId, resuming); + } case POST: - if (!game.isPaused() && !game.isGameOver()) + if (!game.isPaused() && !game.isGameOver()) { postPriority(game, activePlayerId); + } } } private void playExtraSteps(Game game, PhaseStep afterStep) { while (true) { Step extraStep = game.getState().getTurnMods().extraStep(activePlayerId, afterStep); - if (extraStep == null) + if (extraStep == null) { return; + } currentStep = extraStep; playStep(game); }