From ac8962cb29d13cc0a443e7c136f3049680e7ab19 Mon Sep 17 00:00:00 2001 From: igoudt Date: Wed, 11 Jan 2017 09:53:16 +0100 Subject: [PATCH] replaced enum comparison from equals to == --- .../client/deckeditor/DeckEditorPanel.java | 144 +++++++++--------- .../mage/client/dialog/AddLandDialog.java | 2 +- .../plugins/adapters/MageActionCallback.java | 53 +++---- Mage.Common/src/mage/view/CardView.java | 4 +- Mage.Common/src/mage/view/ChatMessage.java | 4 +- Mage.Common/src/mage/view/TableView.java | 39 ++--- .../main/java/mage/server/ChatManager.java | 11 +- .../main/java/mage/server/ChatSession.java | 16 +- .../main/java/mage/server/MageServerImpl.java | 2 +- .../main/java/mage/server/SessionManager.java | 5 +- .../java/mage/server/TableController.java | 39 +++-- .../main/java/mage/server/TableManager.java | 4 +- .../src/main/java/mage/server/User.java | 10 +- .../java/mage/server/game/GamesRoomImpl.java | 6 +- .../tournament/TournamentController.java | 8 +- .../java/mage/server/util/SystemUtil.java | 42 ++--- Mage.Sets/src/mage/cards/e/EnergyField.java | 8 +- Mage.Sets/src/mage/cards/f/FarsightMask.java | 6 +- Mage.Sets/src/mage/cards/f/FrenziedFugue.java | 6 +- Mage.Sets/src/mage/cards/m/MetallicMimic.java | 2 +- .../cards/abilities/keywords/CascadeTest.java | 4 +- .../main/java/mage/abilities/AbilityImpl.java | 27 ++-- .../common/DiesTriggeredAbility.java | 3 +- ...lefieldOrLeavesSourceTriggeredAbility.java | 3 +- .../abilities/effects/common/ManaEffect.java | 2 +- .../PreventDamageToControllerEffect.java | 2 +- .../abilities/keyword/ImproviseAbility.java | 4 +- Mage/src/main/java/mage/game/turn/Phase.java | 2 +- .../main/java/mage/players/PlayerImpl.java | 117 ++++---------- .../src/main/java/mage/target/TargetImpl.java | 4 +- .../common/CardsPutIntoGraveyardWatcher.java | 3 +- 31 files changed, 264 insertions(+), 318 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPanel.java b/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPanel.java index 94319481fe..53333ae05d 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPanel.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPanel.java @@ -44,6 +44,7 @@ import java.util.concurrent.TimeUnit; import javax.swing.*; import javax.swing.Timer; import javax.swing.filechooser.FileFilter; + import mage.cards.Card; import mage.cards.Sets; import mage.cards.decks.Deck; @@ -73,7 +74,6 @@ import mage.view.SimpleCardView; import org.apache.log4j.Logger; /** - * * @author BetaSteward_at_googlemail.com */ public class DeckEditorPanel extends javax.swing.JPanel { @@ -288,7 +288,7 @@ public class DeckEditorPanel extends javax.swing.JPanel { this.deckArea.clearDeckEventListeners(); this.deckArea.addDeckEventListener( (Listener) event -> { - if (mode.equals(DeckEditorMode.FREE_BUILDING)) { + if (mode == DeckEditorMode.FREE_BUILDING){ switch (event.getEventName()) { case "double-click": { SimpleCardView cardView = (SimpleCardView) event.getSource(); @@ -336,7 +336,7 @@ public class DeckEditorPanel extends javax.swing.JPanel { break; } } - } else { + }else{ // constructing phase or sideboarding during match -> card goes always to sideboard switch (event.getEventName()) { case "double-click": @@ -376,7 +376,7 @@ public class DeckEditorPanel extends javax.swing.JPanel { this.deckArea.clearSideboardEventListeners(); this.deckArea.addSideboardEventListener( (Listener) event -> { - if (mode.equals(DeckEditorMode.FREE_BUILDING)) { + if (mode == DeckEditorMode.FREE_BUILDING) { // normal edit mode switch (event.getEventName()) { case "double-click": @@ -598,7 +598,7 @@ public class DeckEditorPanel extends javax.swing.JPanel { AudioManager.playOnCountdown1(); } if (timeToSubmit > 0) { - timeToSubmit --; + timeToSubmit--; btnSubmitTimer.setText("Submit (" + timeToSubmit + ")"); btnSubmitTimer.setToolTipText("Submit your deck in " + timeToSubmit + " seconds!"); } @@ -711,84 +711,84 @@ public class DeckEditorPanel extends javax.swing.JPanel { jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) /*.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE))*/ - .addGroup(jPanel1Layout.createSequentialGroup() - .addGap(6, 6, 6) - .addComponent(lblDeckName) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(txtDeckName, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)) - .addComponent(cardInfoPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addComponent(btnSave) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(btnLoad) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(btnNew) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(btnExit)) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addComponent(btnImport) - .addContainerGap() - .addComponent(btnGenDeck) - .addContainerGap() - .addComponent(btnAddLand) - .addContainerGap() - .addComponent(btnSubmit) - .addContainerGap() - .addComponent(btnSubmitTimer)) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addComponent(txtTimeRemaining)) - ) - .addContainerGap())); + .addGroup(jPanel1Layout.createSequentialGroup() + .addGap(6, 6, 6) + .addComponent(lblDeckName) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(txtDeckName, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)) + .addComponent(cardInfoPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addComponent(btnSave) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btnLoad) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btnNew) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(btnExit)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addComponent(btnImport) + .addContainerGap() + .addComponent(btnGenDeck) + .addContainerGap() + .addComponent(btnAddLand) + .addContainerGap() + .addComponent(btnSubmit) + .addContainerGap() + .addComponent(btnSubmitTimer)) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addComponent(txtTimeRemaining)) + ) + .addContainerGap())); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(txtDeckName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(lblDeckName)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(btnSave) - .addComponent(btnLoad) - .addComponent(btnNew) - .addComponent(btnExit)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(btnImport) - .addComponent(btnGenDeck) - .addComponent(btnAddLand) - .addComponent(btnSubmit) - .addComponent(btnSubmitTimer)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(txtTimeRemaining)) - //.addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, isShowCardInfo ? 30 : 159, Short.MAX_VALUE) - .addComponent(cardInfoPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 104, Short.MAX_VALUE) - .addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))); + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(txtDeckName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lblDeckName)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(btnSave) + .addComponent(btnLoad) + .addComponent(btnNew) + .addComponent(btnExit)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(btnImport) + .addComponent(btnGenDeck) + .addComponent(btnAddLand) + .addComponent(btnSubmit) + .addComponent(btnSubmitTimer)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(txtTimeRemaining)) + //.addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, isShowCardInfo ? 30 : 159, Short.MAX_VALUE) + .addComponent(cardInfoPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 104, Short.MAX_VALUE) + .addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0) - .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 604, Short.MAX_VALUE))); + .addGroup(layout.createSequentialGroup() + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, 0) + .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 604, Short.MAX_VALUE))); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 615, Short.MAX_VALUE)); + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 615, Short.MAX_VALUE)); } /** @@ -1023,7 +1023,7 @@ public class DeckEditorPanel extends javax.swing.JPanel { deck = Deck.load(DeckImporterUtil.importDeck(path), true, true); } catch (GameException ex) { JOptionPane.showMessageDialog(MageFrame.getDesktop(), ex.getMessage(), "Error loading generated deck", JOptionPane.ERROR_MESSAGE); - }catch (DeckGeneratorException ex) { + } catch (DeckGeneratorException ex) { JOptionPane.showMessageDialog(MageFrame.getDesktop(), ex.getMessage(), "Generator error", JOptionPane.ERROR_MESSAGE); } finally { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); diff --git a/Mage.Client/src/main/java/mage/client/dialog/AddLandDialog.java b/Mage.Client/src/main/java/mage/client/dialog/AddLandDialog.java index 97e7ddc771..1220c61867 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/AddLandDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/AddLandDialog.java @@ -72,7 +72,7 @@ public class AddLandDialog extends MageDialog { public void showDialog(Deck deck, DeckEditorMode mode) { this.deck = deck; SortedSet landSetNames = new TreeSet<>(); - if (!mode.equals(DeckEditorMode.FREE_BUILDING)) { + if (mode!=DeckEditorMode.FREE_BUILDING) { // decide from which sets basic lands are taken from for (String setCode : deck.getExpansionSetCodes()) { ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode); diff --git a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java index 396af68d13..31ed09a63c 100644 --- a/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java +++ b/Mage.Client/src/main/java/mage/client/plugins/adapters/MageActionCallback.java @@ -22,6 +22,7 @@ import javax.swing.JPopupMenu; import javax.swing.Popup; import javax.swing.PopupFactory; import javax.swing.SwingUtilities; + import mage.cards.MageCard; import mage.cards.action.ActionCallback; import mage.cards.action.TransferData; @@ -78,6 +79,7 @@ public class MageActionCallback implements ActionCallback { CLOSED, NORMAL, ROTATED } + private Date enlargeredViewOpened; private volatile EnlargedWindowState enlargedWindowState = EnlargedWindowState.CLOSED; //private volatile boolean enlargedImageWindowOpen = false; @@ -156,7 +158,7 @@ public class MageActionCallback implements ActionCallback { || !tooltipCard.equals(data.card) || SessionHandler.getSession() == null || !popupTextWindowOpen - || !enlargedWindowState.equals(EnlargedWindowState.CLOSED)) { + || enlargedWindowState != EnlargedWindowState.CLOSED) { return; } @@ -176,21 +178,21 @@ public class MageActionCallback implements ActionCallback { public void showPopup(final Component popupContainer, final Component infoPane) throws InterruptedException { final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE); SwingUtilities.invokeLater(() -> { - if (!popupTextWindowOpen - || !enlargedWindowState.equals(EnlargedWindowState.CLOSED)) { - return; - } - if (data.locationOnScreen == null) { - data.locationOnScreen = data.component.getLocationOnScreen(); - } + if (!popupTextWindowOpen + || enlargedWindowState != EnlargedWindowState.CLOSED) { + return; + } + if (data.locationOnScreen == null) { + data.locationOnScreen = data.component.getLocationOnScreen(); + } - Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40); - location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, infoPane, parentComponent); - location.translate(-parentPoint.x, -parentPoint.y); - popupContainer.setLocation(location); - popupContainer.setVisible(true); - c.repaint(); - } + Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40); + location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, infoPane, parentComponent); + location.translate(-parentPoint.x, -parentPoint.y); + popupContainer.setLocation(location); + popupContainer.setVisible(true); + c.repaint(); + } ); } }); @@ -402,7 +404,7 @@ public class MageActionCallback implements ActionCallback { } else { popupTextWindowOpen = true; } - if (!enlargedWindowState.equals(EnlargedWindowState.CLOSED)) { + if (enlargedWindowState != EnlargedWindowState.CLOSED) { cancelTimeout(); displayEnlargedCard(mageCard.getOriginal(), transferData); } @@ -417,7 +419,6 @@ public class MageActionCallback implements ActionCallback { /** * Hides the text popup window - * */ public void hideTooltipPopup() { this.tooltipCard = null; @@ -461,13 +462,13 @@ public class MageActionCallback implements ActionCallback { @Override public void mouseWheelMoved(MouseWheelEvent e, TransferData transferData) { int notches = e.getWheelRotation(); - if (!enlargedWindowState.equals(EnlargedWindowState.CLOSED)) { + if (enlargedWindowState != EnlargedWindowState.CLOSED) { // same move direction will be ignored, opposite direction closes the enlarged window if (new Date().getTime() - enlargeredViewOpened.getTime() > 1000) { // if the opening is back more than 1 seconds close anyway hideEnlargedCard(); handleOverNewView(transferData); - } else if (enlargeMode.equals(EnlargeMode.NORMAL)) { + } else if (enlargeMode == EnlargeMode.NORMAL) { if (notches > 0) { hideEnlargedCard(); handleOverNewView(transferData); @@ -491,10 +492,10 @@ public class MageActionCallback implements ActionCallback { * Show the big card image on mouse position while hovering over a card * * @param showAlternative defines if the original image (if it's a copied - * card) or the opposite side of a transformable card will be shown + * card) or the opposite side of a transformable card will be shown */ public void enlargeCard(EnlargeMode showAlternative) { - if (enlargedWindowState.equals(EnlargedWindowState.CLOSED)) { + if (enlargedWindowState == EnlargedWindowState.CLOSED) { this.enlargeMode = showAlternative; CardView cardView = null; if (popupData != null) { @@ -515,7 +516,7 @@ public class MageActionCallback implements ActionCallback { } public void hideEnlargedCard() { - if (!enlargedWindowState.equals(EnlargedWindowState.CLOSED)) { + if (enlargedWindowState != EnlargedWindowState.CLOSED) { enlargedWindowState = EnlargedWindowState.CLOSED; try { Component cardPreviewContainer = MageFrame.getUI().getComponent(MageComponents.CARD_PREVIEW_CONTAINER); @@ -535,21 +536,21 @@ public class MageActionCallback implements ActionCallback { return; } try { - if (enlargedWindowState.equals(EnlargedWindowState.CLOSED)) { + if (enlargedWindowState == EnlargedWindowState.CLOSED) { return; } MageComponents mageComponentCardPreviewContainer; MageComponents mageComponentCardPreviewPane; if (cardView.isToRotate()) { - if (enlargedWindowState.equals(EnlargedWindowState.NORMAL)) { + if (enlargedWindowState == EnlargedWindowState.NORMAL) { hideEnlargedCard(); enlargedWindowState = EnlargedWindowState.ROTATED; } mageComponentCardPreviewContainer = MageComponents.CARD_PREVIEW_CONTAINER_ROTATED; mageComponentCardPreviewPane = MageComponents.CARD_PREVIEW_PANE_ROTATED; } else { - if (enlargedWindowState.equals(EnlargedWindowState.ROTATED)) { + if (enlargedWindowState == EnlargedWindowState.ROTATED) { hideEnlargedCard(); enlargedWindowState = EnlargedWindowState.NORMAL; } @@ -608,7 +609,7 @@ public class MageActionCallback implements ActionCallback { // XXX: scaled to fit width bigCard.setCard(mageCard.getOriginal().getId(), enlargeMode, image, mageCard.getOriginal().getRules(), mageCard.getOriginal().isToRotate()); // if it's an ability, show only the ability text as overlay - if (mageCard.getOriginal().isAbility() && enlargeMode.equals(EnlargeMode.NORMAL)) { + if (mageCard.getOriginal().isAbility() && enlargeMode == EnlargeMode.NORMAL) { bigCard.showTextComponent(); } else { bigCard.hideTextComponent(); diff --git a/Mage.Common/src/mage/view/CardView.java b/Mage.Common/src/mage/view/CardView.java index 5413d844ac..01253de8bf 100644 --- a/Mage.Common/src/mage/view/CardView.java +++ b/Mage.Common/src/mage/view/CardView.java @@ -244,7 +244,7 @@ public class CardView extends SimpleCardView { Zone cardZone = game.getState().getZone(card.getId()); if (card.isFaceDown(game)) { showFaceUp = false; - if (!Zone.BATTLEFIELD.equals(cardZone)) { + if (Zone.BATTLEFIELD!=cardZone) { if (showFaceDownCard) { showFaceUp = true; } @@ -458,7 +458,7 @@ public class CardView extends SimpleCardView { this.rarity = Rarity.NA; this.rules = new ArrayList<>(); this.rules.add(stackAbility.getRule()); - if (stackAbility.getZone().equals(Zone.COMMAND)) { + if (stackAbility.getZone()==Zone.COMMAND) { this.expansionSetCode = stackAbility.getExpansionSetCode(); } } diff --git a/Mage.Common/src/mage/view/ChatMessage.java b/Mage.Common/src/mage/view/ChatMessage.java index a0dbd1e1d8..487e2fbf1c 100644 --- a/Mage.Common/src/mage/view/ChatMessage.java +++ b/Mage.Common/src/mage/view/ChatMessage.java @@ -82,11 +82,11 @@ public class ChatMessage implements Serializable { } public boolean isUserMessage() { - return color != null && (color.equals(MessageColor.BLUE) || color.equals(MessageColor.YELLOW)); + return color != null && (color==MessageColor.BLUE || color==MessageColor.YELLOW); } public boolean isStatusMessage() { - return color != null && color.equals(MessageColor.ORANGE); + return color != null && color== MessageColor.ORANGE; } public String getUsername() { diff --git a/Mage.Common/src/mage/view/TableView.java b/Mage.Common/src/mage/view/TableView.java index 4d4f7373dd..52051be04c 100644 --- a/Mage.Common/src/mage/view/TableView.java +++ b/Mage.Common/src/mage/view/TableView.java @@ -33,6 +33,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.UUID; + import mage.constants.SkillLevel; import mage.constants.TableState; import mage.game.Game; @@ -43,7 +44,6 @@ import mage.game.match.MatchPlayer; import mage.game.tournament.TournamentPlayer; /** - * * @author BetaSteward_at_googlemail.com */ public class TableView implements Serializable { @@ -67,19 +67,19 @@ public class TableView implements Serializable { private final boolean rated; private final boolean passworded; - public TableView(Table table) { + public TableView(Table table) { this.tableId = table.getId(); this.gameType = table.getGameType(); this.tableName = table.getName(); String tableNameInfo = null; if (tableName != null && !tableName.isEmpty()) { - tableNameInfo = " [" + table.getName() + "]"; + tableNameInfo = " [" + table.getName() + "]"; } this.controllerName = table.getControllerName(); this.tableState = table.getState(); - if (table.getState().equals(TableState.WAITING) || - table.getState().equals(TableState.READY_TO_START) || - table.getState().equals(TableState.STARTING) ) { + if (table.getState() == TableState.WAITING || + table.getState() == TableState.READY_TO_START || + table.getState() == TableState.STARTING) { this.createTime = table.getCreateTime(); } else { if (table.isTournament()) { @@ -89,22 +89,22 @@ public class TableView implements Serializable { } } this.isTournament = table.isTournament(); - for (Seat seat: table.getSeats()) { + for (Seat seat : table.getSeats()) { seats.add(new SeatView(seat)); } if (!table.isTournament()) { - // MATCH - if (table.getState().equals(TableState.WAITING) || table.getState().equals(TableState.READY_TO_START)) { - tableStateText = table.getState().toString() + " (" + table.getMatch().getPlayers().size() + "/"+ table.getSeats().length + ")"; + // MATCH + if (table.getState()==TableState.WAITING || table.getState()==TableState.READY_TO_START) { + tableStateText = table.getState().toString() + " (" + table.getMatch().getPlayers().size() + "/" + table.getSeats().length + ")"; } else { tableStateText = table.getState().toString(); } - for (Game game: table.getMatch().getGames()) { + for (Game game : table.getMatch().getGames()) { games.add(game.getId()); } StringBuilder sb = new StringBuilder(); StringBuilder sbScore = new StringBuilder(); - for(MatchPlayer matchPlayer: table.getMatch().getPlayers()) { + for (MatchPlayer matchPlayer : table.getMatch().getPlayers()) { if (matchPlayer.getPlayer() == null) { sb.append(", ").append("[unknown]"); sbScore.append("-").append(matchPlayer.getWins()); @@ -112,7 +112,7 @@ public class TableView implements Serializable { sb.append(", ").append(matchPlayer.getName()); sbScore.append("-").append(matchPlayer.getWins()); } else { - sbScore.insert(0,matchPlayer.getWins()).insert(0," Score: "); + sbScore.insert(0, matchPlayer.getWins()).insert(0, " Score: "); } } if (table.getMatch().getDraws() > 0) { @@ -138,12 +138,12 @@ public class TableView implements Serializable { this.rated = table.getMatch().getOptions().isRated(); this.passworded = !table.getMatch().getOptions().getPassword().isEmpty(); } else { - // TOURNAMENT + // TOURNAMENT if (table.getTournament().getOptions().getNumberRounds() > 0) { this.gameType = new StringBuilder(this.gameType).append(" ").append(table.getTournament().getOptions().getNumberRounds()).append(" Rounds").toString(); } StringBuilder sb1 = new StringBuilder(); - for (TournamentPlayer tp: table.getTournament().getPlayers()) { + for (TournamentPlayer tp : table.getTournament().getPlayers()) { if (!tp.getPlayer().getName().equals(table.getControllerName())) { sb1.append(", ").append(tp.getPlayer().getName()); } @@ -163,7 +163,7 @@ public class TableView implements Serializable { infoText.append(" Fr.Mul: ").append(table.getTournament().getOptions().getMatchOptions().getFreeMulligans()); } if (table.getTournament().getTournamentType().isLimited()) { - infoText.append(" Constr.: ").append(table.getTournament().getOptions().getLimitedOptions().getConstructionTime()/60).append(" Min."); + infoText.append(" Constr.: ").append(table.getTournament().getOptions().getLimitedOptions().getConstructionTime() / 60).append(" Min."); } break; case DUELING: @@ -172,13 +172,13 @@ public class TableView implements Serializable { case DRAFTING: Draft draft = table.getTournament().getDraft(); if (draft != null) { - stateText.append(" ").append(draft.getBoosterNum()).append("/").append(draft.getCardNum() -1); + stateText.append(" ").append(draft.getBoosterNum()).append("/").append(draft.getCardNum() - 1); } default: } this.additionalInfo = infoText.toString(); this.tableStateText = stateText.toString(); - this.deckType = table.getDeckType() + " " + table.getTournament().getBoosterInfo() + (tableNameInfo != null ? tableNameInfo : ""); + this.deckType = table.getDeckType() + " " + table.getTournament().getBoosterInfo() + (tableNameInfo != null ? tableNameInfo : ""); this.skillLevel = table.getTournament().getOptions().getMatchOptions().getSkillLevel(); this.quitRatio = Integer.toString(table.getTournament().getOptions().getQuitRatio()); this.limited = table.getTournament().getOptions().getMatchOptions().isLimited(); @@ -226,6 +226,7 @@ public class TableView implements Serializable { public boolean isTournament() { return this.isTournament; } + public String getAdditionalInfo() { return this.additionalInfo; } @@ -249,7 +250,7 @@ public class TableView implements Serializable { public boolean isRated() { return rated; } - + public boolean isPassworded() { return passworded; } diff --git a/Mage.Server/src/main/java/mage/server/ChatManager.java b/Mage.Server/src/main/java/mage/server/ChatManager.java index d9581e0cc7..fe8305bdc8 100644 --- a/Mage.Server/src/main/java/mage/server/ChatManager.java +++ b/Mage.Server/src/main/java/mage/server/ChatManager.java @@ -35,6 +35,7 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; + import mage.cards.repository.CardInfo; import mage.cards.repository.CardRepository; import mage.server.util.SystemUtil; @@ -44,7 +45,6 @@ import mage.view.ChatMessage.SoundToPlay; import org.apache.log4j.Logger; /** - * * @author BetaSteward_at_googlemail.com */ public class ChatManager { @@ -116,9 +116,9 @@ public class ChatManager { } return false; } - + final Pattern cardNamePattern = Pattern.compile("\\[(.*?)\\]"); - + public void broadcast(UUID chatId, String userName, String message, MessageColor color, boolean withTime, MessageType messageType, SoundToPlay soundToPlay) { ChatSession chatSession = chatSessions.get(chatId); if (chatSession != null) { @@ -132,7 +132,7 @@ public class ChatManager { } } - if (!messageType.equals(MessageType.GAME)) { + if (messageType != MessageType.GAME) { User user = UserManager.getInstance().getUserByName(userName); if (message != null && userName != null && !userName.equals("")) { @@ -177,7 +177,7 @@ public class ChatManager { } } - if (messageType.equals(MessageType.TALK)) { + if (messageType == MessageType.TALK) { if (user != null) { if (user.getChatLockedUntil() != null) { if (user.getChatLockedUntil().compareTo(Calendar.getInstance().getTime()) > 0) { @@ -249,7 +249,6 @@ public class ChatManager { } /** - * * use mainly for announcing that a user connection was lost or that a user * has reconnected * diff --git a/Mage.Server/src/main/java/mage/server/ChatSession.java b/Mage.Server/src/main/java/mage/server/ChatSession.java index 4db5716b4b..9c2a6e8866 100644 --- a/Mage.Server/src/main/java/mage/server/ChatSession.java +++ b/Mage.Server/src/main/java/mage/server/ChatSession.java @@ -27,12 +27,6 @@ */ package mage.server; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashSet; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; import mage.interfaces.callback.ClientCallback; import mage.view.ChatMessage; import mage.view.ChatMessage.MessageColor; @@ -40,8 +34,14 @@ import mage.view.ChatMessage.MessageType; import mage.view.ChatMessage.SoundToPlay; import org.apache.log4j.Logger; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.HashSet; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + /** - * * @author BetaSteward_at_googlemail.com */ public class ChatSession { @@ -79,7 +79,7 @@ public class ChatSession { } if (userId != null && clients.containsKey(userId)) { String userName = clients.get(userId); - if (!reason.equals(DisconnectReason.LostConnection)) { // for lost connection the user will be reconnected or session expire so no remove of chat yet + if (reason != DisconnectReason.LostConnection) { // for lost connection the user will be reconnected or session expire so no remove of chat yet clients.remove(userId); logger.debug(userName + "(" + reason.toString() + ")" + " removed from chatId " + chatId); } diff --git a/Mage.Server/src/main/java/mage/server/MageServerImpl.java b/Mage.Server/src/main/java/mage/server/MageServerImpl.java index 5e14476ce6..2512bf2aaf 100644 --- a/Mage.Server/src/main/java/mage/server/MageServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/MageServerImpl.java @@ -580,7 +580,7 @@ public class MageServerImpl implements MageServer { @Override public boolean leaveTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException { TableState tableState = TableManager.getInstance().getController(tableId).getTableState(); - if (!tableState.equals(TableState.WAITING) && !tableState.equals(TableState.READY_TO_START)) { + if (tableState!=TableState.WAITING && tableState!=TableState.READY_TO_START) { // table was already started, so player can't leave anymore now return false; } diff --git a/Mage.Server/src/main/java/mage/server/SessionManager.java b/Mage.Server/src/main/java/mage/server/SessionManager.java index ad824fdcc7..4fdc16b100 100644 --- a/Mage.Server/src/main/java/mage/server/SessionManager.java +++ b/Mage.Server/src/main/java/mage/server/SessionManager.java @@ -30,13 +30,13 @@ package mage.server; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; + import mage.MageException; import mage.players.net.UserData; import org.apache.log4j.Logger; import org.jboss.remoting.callback.InvokerCallbackHandler; /** - * * @author BetaSteward_at_googlemail.com */ public class SessionManager { @@ -47,6 +47,7 @@ public class SessionManager { public static SessionManager getInstance() { return INSTANCE; } + private final ConcurrentHashMap sessions = new ConcurrentHashMap<>(); public Session getSession(String sessionId) { @@ -127,7 +128,7 @@ public class SessionManager { public void disconnect(String sessionId, DisconnectReason reason) { Session session = sessions.get(sessionId); if (session != null) { - if (!reason.equals(DisconnectReason.AdminDisconnect)) { + if (reason != DisconnectReason.AdminDisconnect) { if (!sessions.containsKey(sessionId)) { // session was removed meanwhile by another thread so we can return return; diff --git a/Mage.Server/src/main/java/mage/server/TableController.java b/Mage.Server/src/main/java/mage/server/TableController.java index e19dfefc47..bf42791c75 100644 --- a/Mage.Server/src/main/java/mage/server/TableController.java +++ b/Mage.Server/src/main/java/mage/server/TableController.java @@ -34,6 +34,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; + import mage.MageException; import mage.cards.decks.Deck; import mage.cards.decks.DeckCardLists; @@ -72,7 +73,6 @@ import mage.view.ChatMessage; import org.apache.log4j.Logger; /** - * * @author BetaSteward_at_googlemail.com */ public class TableController { @@ -294,14 +294,14 @@ public class TableController { user.showUserMessage("Join Table", message); return false; } - + // Check power level for table (currently only used for EDH/Commander table) int edhPowerLevel = table.getMatch().getOptions().getEdhPowerLevel(); if (edhPowerLevel > 0 && table.getValidator().getName().toLowerCase().equals("commander")) { int deckEdhPowerLevel = table.getValidator().getEdhPowerLevel(deck); if (deckEdhPowerLevel > edhPowerLevel) { String message = new StringBuilder("Your deck appears to be too powerful for this table.\n\nReduce the number of extra turn cards, infect, counters, fogs, reconsider your commander. ") - .append("\nThe table requirement has a maximum power level of ").append(edhPowerLevel).append (" whilst your deck has a calculated power level of ") + .append("\nThe table requirement has a maximum power level of ").append(edhPowerLevel).append(" whilst your deck has a calculated power level of ") .append(deckEdhPowerLevel).toString(); user.showUserMessage("Join Table", message); return false; @@ -412,7 +412,7 @@ public class TableController { } else { logger.fatal("Tournament == null table: " + table.getId() + " userId: " + userId); } - } else if (TableState.SIDEBOARDING.equals(table.getState())) { + } else if (TableState.SIDEBOARDING == table.getState()) { match.updateDeck(playerId, deck); } else { // deck was meanwhile submitted so the autoupdate can be ignored @@ -438,7 +438,7 @@ public class TableController { } } -// public boolean replayTable(UUID userId) { + // public boolean replayTable(UUID userId) { // if (table.getState() != TableState.FINISHED) { // return false; // } @@ -476,8 +476,8 @@ public class TableController { } if (table != null && this.userId != null && this.userId.equals(userId) // tourn. sub tables have no creator user - && (table.getState().equals(TableState.WAITING) - || table.getState().equals(TableState.READY_TO_START))) { + && (table.getState() == TableState.WAITING + || table.getState() == TableState.READY_TO_START)) { // table not started yet and user is the owner, remove the table TableManager.getInstance().removeTable(table.getId()); } else { @@ -500,7 +500,7 @@ public class TableController { logger.debug("User not found - userId: " + userId + " tableId:" + table.getId()); } userPlayerMap.remove(userId); - } else if (!table.getState().equals(TableState.FINISHED)) { + } else if (table.getState() != TableState.FINISHED) { if (table.isTournament()) { logger.debug("Quit tournament sub tables for userId: " + userId); TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId); @@ -517,7 +517,7 @@ public class TableController { } match.quitMatch(playerId); } else { - if (table.getState().equals(TableState.SIDEBOARDING)) { + if (table.getState() == TableState.SIDEBOARDING) { if (!matchPlayer.isDoneSideboarding()) { // submit deck to finish sideboarding and trigger match start / end matchPlayer.submitDeck(matchPlayer.getDeck()); @@ -546,7 +546,7 @@ public class TableController { } public synchronized void startMatch() { - if (table.getState().equals(TableState.STARTING)) { + if (table.getState() == TableState.STARTING) { try { if (table.isTournamentSubTable()) { logger.info("Tourn. match started id:" + match.getId() + " tournId: " + table.getTournament().getId()); @@ -630,7 +630,7 @@ public class TableController { public synchronized void startTournament(UUID userId) { try { - if (userId.equals(this.userId) && table.getState().equals(TableState.STARTING)) { + if (userId.equals(this.userId) && table.getState() == TableState.STARTING) { tournament.setStartTime(); TournamentManager.getInstance().createTournamentSession(tournament, userPlayerMap, table.getId()); for (Entry entry : userPlayerMap.entrySet()) { @@ -762,7 +762,6 @@ public class TableController { /** * Tables of normal matches or tournament sub tables are no longer needed, * if the match ends. - * */ private void closeTable() { this.matchEnd(); @@ -778,7 +777,7 @@ public class TableController { if (!matchPlayer.hasQuit()) { User user = UserManager.getInstance().getUser(entry.getKey()); if (user != null) { - if (table.getState().equals(TableState.SIDEBOARDING)) { + if (table.getState()==TableState.SIDEBOARDING) { StringBuilder sb = new StringBuilder(); if (table.isTournamentSubTable()) { sb.append("Your tournament match of round "); @@ -843,7 +842,7 @@ public class TableController { } public void swapSeats(int seatNum1, int seatNum2) { - if (table.getState().equals(TableState.READY_TO_START)) { + if (table.getState()==TableState.READY_TO_START) { if (seatNum1 >= 0 && seatNum2 >= 0 && seatNum1 < table.getSeats().length && seatNum2 < table.getSeats().length) { Player swapPlayer = table.getSeats()[seatNum1].getPlayer(); String swapType = table.getSeats()[seatNum1].getPlayerType(); @@ -876,7 +875,7 @@ public class TableController { public boolean isTournamentStillValid() { if (table.getTournament() != null) { - if (!table.getState().equals(TableState.WAITING) && !table.getState().equals(TableState.READY_TO_START) && !table.getState().equals(TableState.STARTING)) { + if (table.getState() != TableState.WAITING && table.getState() != TableState.READY_TO_START && table.getState() != TableState.STARTING) { TournamentController tournamentController = TournamentManager.getInstance().getTournamentController(table.getTournament().getId()); if (tournamentController != null) { return tournamentController.isTournamentStillValid(table.getState()); @@ -923,7 +922,7 @@ public class TableController { int humanPlayers = 0; int aiPlayers = 0; int validHumanPlayers = 0; - if (!(table.getState().equals(TableState.WAITING) || table.getState().equals(TableState.STARTING) || table.getState().equals(TableState.READY_TO_START))) { + if (!(table.getState() == TableState.WAITING || table.getState() == TableState.STARTING || table.getState() == TableState.READY_TO_START)) { if (match == null) { logger.debug("- Match table with no match:"); logger.debug("-- matchId:" + match.getId() + " [" + match.getName() + "]"); @@ -947,9 +946,9 @@ public class TableController { } if (matchPlayer.getPlayer().isHuman()) { humanPlayers++; - if ((table.getState().equals(TableState.WAITING) - || table.getState().equals(TableState.STARTING) - || table.getState().equals(TableState.READY_TO_START)) + if ((table.getState() == TableState.WAITING + || table.getState() == TableState.STARTING + || table.getState() == TableState.READY_TO_START) || !match.isDoneSideboarding() || (!matchPlayer.hasQuit() && match.getGame() != null && matchPlayer.getPlayer().isInGame())) { User user = UserManager.getInstance().getUser(userPlayerEntry.getKey()); @@ -990,7 +989,7 @@ public class TableController { } public synchronized boolean changeTableStateToStarting() { - if (!getTable().getState().equals(TableState.READY_TO_START)) { + if (getTable().getState() != TableState.READY_TO_START) { // tournament is not ready, can't start return false; } diff --git a/Mage.Server/src/main/java/mage/server/TableManager.java b/Mage.Server/src/main/java/mage/server/TableManager.java index 155ffdf59b..0eb78b7c84 100644 --- a/Mage.Server/src/main/java/mage/server/TableManager.java +++ b/Mage.Server/src/main/java/mage/server/TableManager.java @@ -344,7 +344,7 @@ public class TableManager { } // If table is not finished, the table has to be removed completly because it's not a normal state (if finished it will be removed in GamesRoomImpl.Update()) - if (!table.getState().equals(TableState.FINISHED)) { + if (table.getState()!=TableState.FINISHED) { if (game != null) { GameManager.getInstance().removeGame(game.getId()); } @@ -395,7 +395,7 @@ public class TableManager { tableCopy.addAll(tables.values()); for (Table table : tableCopy) { try { - if (!table.getState().equals(TableState.FINISHED)) { + if (table.getState()!=TableState.FINISHED) { // remove tables and games not valid anymore logger.debug(table.getId() + " [" + table.getName()+ "] " + formatter.format(table.getStartTime() == null ? table.getCreateTime() : table.getCreateTime()) +" (" + table.getState().toString() + ") " + (table.isTournament() ? "- Tournament":"")); TableController tableController = getController(table.getId()); diff --git a/Mage.Server/src/main/java/mage/server/User.java b/Mage.Server/src/main/java/mage/server/User.java index ef37a1e07b..23469e48c0 100644 --- a/Mage.Server/src/main/java/mage/server/User.java +++ b/Mage.Server/src/main/java/mage/server/User.java @@ -37,6 +37,7 @@ import java.util.Map.Entry; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; + import mage.cards.decks.Deck; import mage.constants.ManaType; import mage.constants.TableState; @@ -61,7 +62,6 @@ import mage.view.TableClientMessage; import org.apache.log4j.Logger; /** - * * @author BetaSteward_at_googlemail.com */ public class User { @@ -199,7 +199,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.getInstance().stopWatching(gameId, userId); iterator.remove(); @@ -208,7 +208,7 @@ public class User { } public boolean isConnected() { - return userState.equals(UserState.Connected) || userState.equals(UserState.Reconnected); + return userState == UserState.Connected || userState == UserState.Reconnected; } public String getDisconnectDuration() { @@ -762,7 +762,7 @@ public class User { public int getNumberOfNotStartedTables() { int number = 0; for (Table table : tables.values()) { - if (table.getState().equals(TableState.WAITING) || table.getState().equals(TableState.STARTING)) { + if (table.getState() == TableState.WAITING || table.getState() == TableState.STARTING) { number++; } } @@ -772,7 +772,7 @@ public class User { public int getNumberOfNotFinishedTables() { int number = 0; for (Table table : tables.values()) { - if (table.getState().equals(TableState.FINISHED)) { + if (table.getState() == TableState.FINISHED) { number++; } else { TableController tableController = TableManager.getInstance().getController(table.getId()); diff --git a/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java b/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java index 521b770a0d..6f6d57d876 100644 --- a/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java +++ b/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java @@ -37,6 +37,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; + import mage.MageException; import mage.cards.decks.DeckCardLists; import mage.constants.TableState; @@ -58,7 +59,6 @@ import mage.view.UsersView; import org.apache.log4j.Logger; /** - * * @author BetaSteward_at_googlemail.com */ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable { @@ -232,11 +232,11 @@ class TableListSorter implements Comparator { @Override public int compare(Table one, Table two) { if (one.getState() != null && two.getState() != null) { - if (!TableState.SIDEBOARDING.equals(one.getState()) && !TableState.DUELING.equals(one.getState())) { + if (TableState.SIDEBOARDING != one.getState() && TableState.DUELING != one.getState()) { if (one.getState().compareTo(two.getState()) != 0) { return one.getState().compareTo(two.getState()); } - } else if (!TableState.SIDEBOARDING.equals(two.getState()) && !TableState.DUELING.equals(two.getState())) { + } else if (TableState.SIDEBOARDING != two.getState() && TableState.DUELING != two.getState()) { if (one.getState().compareTo(two.getState()) != 0) { return one.getState().compareTo(two.getState()); } diff --git a/Mage.Server/src/main/java/mage/server/tournament/TournamentController.java b/Mage.Server/src/main/java/mage/server/tournament/TournamentController.java index c81ef1a64a..1b62b18759 100644 --- a/Mage.Server/src/main/java/mage/server/tournament/TournamentController.java +++ b/Mage.Server/src/main/java/mage/server/tournament/TournamentController.java @@ -302,7 +302,7 @@ public class TournamentController { } private void initTournament() { - if (!TableManager.getInstance().getTable(tableId).getState().equals(TableState.DUELING)) { + if (TableManager.getInstance().getTable(tableId).getState()!=TableState.DUELING) { TableManager.getInstance().initTournament(tableId); } } @@ -385,7 +385,7 @@ public class TournamentController { // quit active matches of that tournament TableManager.getInstance().userQuitTournamentSubTables(tournament.getId(), userId); status = TourneyQuitStatus.DURING_ROUND; - } else if (tournamentPlayer.getState().equals(TournamentPlayerState.DRAFTING)) { + } else if (tournamentPlayer.getState()==TournamentPlayerState.DRAFTING) { info = "during Draft phase"; if (!checkToReplaceDraftPlayerByAi(userId, tournamentPlayer)) { this.abortDraftTournament(); @@ -399,7 +399,7 @@ public class TournamentController { } } status = TourneyQuitStatus.DURING_DRAFTING; - } else if (tournamentPlayer.getState().equals(TournamentPlayerState.CONSTRUCTING)) { + } else if (tournamentPlayer.getState()==TournamentPlayerState.CONSTRUCTING) { info = "during Construction phase"; status = TourneyQuitStatus.DURING_CONSTRUCTION; } else { @@ -523,7 +523,7 @@ public class TournamentController { } } } - if (activePlayers < 2 && !tableState.equals(TableState.WAITING)) { + if (activePlayers < 2 && tableState!=TableState.WAITING) { logger.debug("Tournament has less than 2 active players - tournamentId: " + tournament.getId() + " state: " + tableState.toString()); return false; } diff --git a/Mage.Server/src/main/java/mage/server/util/SystemUtil.java b/Mage.Server/src/main/java/mage/server/util/SystemUtil.java index 3b55b760c7..00cd7ea313 100644 --- a/Mage.Server/src/main/java/mage/server/util/SystemUtil.java +++ b/Mage.Server/src/main/java/mage/server/util/SystemUtil.java @@ -1,16 +1,5 @@ package mage.server.util; -import java.io.File; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Scanner; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import mage.cards.Card; import mage.cards.repository.CardInfo; import mage.cards.repository.CardRepository; @@ -19,6 +8,14 @@ import mage.game.Game; import mage.players.Player; import mage.util.RandomUtil; +import java.io.File; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * @author nantuko */ @@ -129,14 +126,17 @@ public class SystemUtil { // Put the card in Exile to start. Otherwise the game doesn't know where to remove the card from. game.getExile().getPermanentExile().add(card); game.setZone(card.getId(), Zone.EXILED); - if (zone.equals(Zone.BATTLEFIELD)) { - card.putOntoBattlefield(game, Zone.EXILED, null, player.getId()); - } else if (zone.equals(Zone.LIBRARY)) { - card.setZone(Zone.LIBRARY, game); - game.getExile().getPermanentExile().remove(card); - player.getLibrary().putOnTop(card, game); - } else { - card.moveToZone(zone, null, game, false); + switch (zone) { + case BATTLEFIELD: + card.putOntoBattlefield(game, Zone.EXILED, null, player.getId()); + break; + case LIBRARY: + card.setZone(Zone.LIBRARY, game); + game.getExile().getPermanentExile().remove(card); + player.getLibrary().putOnTop(card, game); + break; + default: + card.moveToZone(zone, null, game, false); } logger.info("Added card to player's " + zone.toString() + ": " + card.getName() + ", player = " + player.getName()); } @@ -176,8 +176,8 @@ public class SystemUtil { /** * Get a diff between two dates * - * @param date1 the oldest date - * @param date2 the newest date + * @param date1 the oldest date + * @param date2 the newest date * @param timeUnit the unit in which you want the diff * @return the diff value, in the provided unit */ diff --git a/Mage.Sets/src/mage/cards/e/EnergyField.java b/Mage.Sets/src/mage/cards/e/EnergyField.java index 34d5b3bb32..5e601c6636 100644 --- a/Mage.Sets/src/mage/cards/e/EnergyField.java +++ b/Mage.Sets/src/mage/cards/e/EnergyField.java @@ -28,6 +28,7 @@ package mage.cards.e; import java.util.UUID; + import mage.abilities.Ability; import mage.abilities.common.PutCardIntoGraveFromAnywhereAllTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; @@ -43,13 +44,12 @@ import mage.game.Game; import mage.game.events.GameEvent; /** - * * @author Plopman */ public class EnergyField extends CardImpl { public EnergyField(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{U}"); // Prevent all damage that would be dealt to you by sources you don't control. @@ -100,8 +100,8 @@ class EnergyFieldEffect extends PreventionEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER)) { - if (event.getTargetId().equals(source.getControllerId()) && game.getControllerId(event.getSourceId()) != source.getControllerId()){ + if (event.getType() == GameEvent.EventType.DAMAGE_PLAYER) { + if (event.getTargetId().equals(source.getControllerId()) && game.getControllerId(event.getSourceId()) != source.getControllerId()) { return super.applies(event, source, game); } } diff --git a/Mage.Sets/src/mage/cards/f/FarsightMask.java b/Mage.Sets/src/mage/cards/f/FarsightMask.java index 5f70115d9c..b395b3a8b4 100644 --- a/Mage.Sets/src/mage/cards/f/FarsightMask.java +++ b/Mage.Sets/src/mage/cards/f/FarsightMask.java @@ -28,6 +28,7 @@ package mage.cards.f; import java.util.UUID; + import mage.constants.CardType; import mage.constants.Zone; import mage.abilities.TriggeredAbilityImpl; @@ -39,13 +40,12 @@ import mage.game.events.GameEvent; import mage.game.permanent.Permanent; /** - * * @author North */ public class FarsightMask extends CardImpl { public FarsightMask(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{5}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{5}"); // Whenever a source an opponent controls deals damage to you, if Farsight Mask is untapped, you may draw a card. this.addAbility(new FarsightMaskTriggeredAbility()); @@ -78,7 +78,7 @@ class FarsightMaskTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkEventType(GameEvent event, Game game) { - return event.getType().equals(GameEvent.EventType.DAMAGED_PLAYER); + return event.getType() == GameEvent.EventType.DAMAGED_PLAYER; } @Override diff --git a/Mage.Sets/src/mage/cards/f/FrenziedFugue.java b/Mage.Sets/src/mage/cards/f/FrenziedFugue.java index 39bc33a5a3..27ab625d1f 100644 --- a/Mage.Sets/src/mage/cards/f/FrenziedFugue.java +++ b/Mage.Sets/src/mage/cards/f/FrenziedFugue.java @@ -28,6 +28,7 @@ package mage.cards.f; import java.util.UUID; + import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.Effect; @@ -51,7 +52,6 @@ import mage.target.TargetPermanent; import mage.target.targetpointer.FixedTarget; /** - * * @author LevelX2 */ public class FrenziedFugue extends CardImpl { @@ -98,13 +98,13 @@ class FrenziedFugueTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkEventType(GameEvent event, Game game) { - return event.getType().equals(EventType.ENTERS_THE_BATTLEFIELD) || event.getType().equals(EventType.UPKEEP_STEP_PRE); + return event.getType() == EventType.ENTERS_THE_BATTLEFIELD || event.getType() == EventType.UPKEEP_STEP_PRE; } @Override public boolean checkTrigger(GameEvent event, Game game) { boolean result; - if (event.getType().equals(EventType.ENTERS_THE_BATTLEFIELD)) { + if (event.getType()==EventType.ENTERS_THE_BATTLEFIELD) { result = event.getTargetId().equals(this.getSourceId()); } else { result = event.getPlayerId().equals(this.getControllerId()); diff --git a/Mage.Sets/src/mage/cards/m/MetallicMimic.java b/Mage.Sets/src/mage/cards/m/MetallicMimic.java index db9227580f..7dad26c499 100644 --- a/Mage.Sets/src/mage/cards/m/MetallicMimic.java +++ b/Mage.Sets/src/mage/cards/m/MetallicMimic.java @@ -135,7 +135,7 @@ class MetallicMimicReplacementEffect extends ReplacementEffectImpl { return enteringCreature != null && sourcePermanent != null && enteringCreature.getControllerId().equals(source.getControllerId()) && enteringCreature.getCardType().contains(CardType.CREATURE) - && enteringCreature.getSubtype(game).contains((String) game.getState().getValue(sourcePermanent.getId() + "_type")) + && enteringCreature.getSubtype(game).contains(game.getState().getValue(sourcePermanent.getId() + "_type")) && !event.getTargetId().equals(source.getSourceId()); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/CascadeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/CascadeTest.java index 4fe810f573..f5aa2e4510 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/CascadeTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/CascadeTest.java @@ -174,8 +174,8 @@ public class CascadeTest extends CardTestPlayerBase { // Choose one - You draw five cards and you lose 5 life; // or put an X/X black Demon creature token with flying onto the battlefield, where X is the number of cards in your hand as the token enters the battlefield. // Entwine {4} (Choose both if you pay the entwine cost.) - //addCard(Zone.LIBRARY, playerA, "Promise of Power", 10); - addCard(Zone.LIBRARY, playerA, "Silvercoat Lion", 2); + addCard(Zone.LIBRARY, playerA, "Promise of Power", 1); + // addCard(Zone.LIBRARY, playerA, "Silvercoat Lion", 2); addCard(Zone.BATTLEFIELD, playerA, "Plains", 3); addCard(Zone.BATTLEFIELD, playerA, "Forest", 3); diff --git a/Mage/src/main/java/mage/abilities/AbilityImpl.java b/Mage/src/main/java/mage/abilities/AbilityImpl.java index bb8b1497fd..a259bee667 100644 --- a/Mage/src/main/java/mage/abilities/AbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilityImpl.java @@ -30,6 +30,7 @@ package mage.abilities; import java.util.ArrayList; import java.util.List; import java.util.UUID; + import mage.MageObject; import mage.MageObjectReference; import mage.Mana; @@ -76,7 +77,6 @@ import mage.watchers.Watcher; import org.apache.log4j.Logger; /** - * * @author BetaSteward_at_googlemail.com */ public abstract class AbilityImpl implements Ability { @@ -197,7 +197,7 @@ public abstract class AbilityImpl implements Ability { boolean effectResult = effect.apply(game, this); result &= effectResult; if (logger.isDebugEnabled()) { - if (!this.getAbilityType().equals(AbilityType.MANA)) { + if (this.getAbilityType() != AbilityType.MANA) { if (!effectResult) { if (this.getSourceId() != null) { MageObject mageObject = game.getObject(this.getSourceId()); @@ -267,7 +267,7 @@ public abstract class AbilityImpl implements Ability { * If the player wishes to splice any cards onto the spell (see rule 702.45), he * or she reveals those cards in his or her hand. */ - if (this.abilityType.equals(AbilityType.SPELL)) { + if (this.abilityType == AbilityType.SPELL) { game.getContinuousEffects().applySpliceEffects(this, game); } @@ -290,8 +290,8 @@ public abstract class AbilityImpl implements Ability { // or her intentions to pay any or all of those costs (see rule 601.2e). // A player can't apply two alternative methods of casting or two alternative costs to a single spell. if (!activateAlternateOrAdditionalCosts(sourceObject, noMana, controller, game)) { - if (getAbilityType().equals(AbilityType.SPELL) - && ((SpellAbility) this).getSpellAbilityType().equals(SpellAbilityType.FACE_DOWN_CREATURE)) { + if (getAbilityType() == AbilityType.SPELL + && ((SpellAbility) this).getSpellAbilityType() == SpellAbilityType.FACE_DOWN_CREATURE) { return false; } } @@ -302,7 +302,7 @@ public abstract class AbilityImpl implements Ability { VariableManaCost variableManaCost = handleManaXCosts(game, noMana, controller); String announceString = handleOtherXCosts(game, controller); // For effects from cards like Void Winnower x costs have to be set - if (this.getAbilityType().equals(AbilityType.SPELL) + if (this.getAbilityType() == AbilityType.SPELL && game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE, getId(), getSourceId(), getControllerId()), this)) { return false; } @@ -325,7 +325,7 @@ public abstract class AbilityImpl implements Ability { // and/or zones become the target of a spell trigger at this point; they'll wait to be put on // the stack until the spell has finished being cast.) - if (sourceObject != null && !this.getAbilityType().equals(AbilityType.TRIGGERED)) { // triggered abilities check this already in playerImpl.triggerAbility + if (sourceObject != null && this.getAbilityType() != AbilityType.TRIGGERED) { // triggered abilities check this already in playerImpl.triggerAbility sourceObject.adjustTargets(this, game); } // Flashback abilities haven't made the choices the underlying spell might need for targeting. @@ -408,7 +408,7 @@ public abstract class AbilityImpl implements Ability { } activated = true; // fire if tapped for mana (may only fire now because else costs of ability itself can be payed with mana of abilities that trigger for that event - if (this.getAbilityType().equals(AbilityType.MANA)) { + if (this.getAbilityType() == AbilityType.MANA) { for (Cost cost : costs) { if (cost instanceof TapSourceCost) { Mana mana = null; @@ -466,10 +466,10 @@ public abstract class AbilityImpl implements Ability { } // controller specific alternate spell costs if (!noMana && !alternativeCostisUsed) { - if (this.getAbilityType().equals(AbilityType.SPELL) + if (this.getAbilityType() == AbilityType.SPELL // 117.9a Only one alternative cost can be applied to any one spell as it’s being cast. // So an alternate spell ability can't be paid with Omniscience - && !((SpellAbility) this).getSpellAbilityType().equals(SpellAbilityType.BASE_ALTERNATE)) { + && ((SpellAbility) this).getSpellAbilityType() != SpellAbilityType.BASE_ALTERNATE) { for (AlternativeSourceCosts alternativeSourceCosts : controller.getAlternativeSourceCosts()) { if (alternativeSourceCosts.isAvailable(this, game)) { if (alternativeSourceCosts.askToActivateAlternativeCosts(this, game)) { @@ -489,10 +489,8 @@ public abstract class AbilityImpl implements Ability { * Handles the setting of non mana X costs * * @param controller - * * @param game * @return announce message - * */ protected String handleOtherXCosts(Game game, Player controller) { String announceString = null; @@ -873,7 +871,6 @@ public abstract class AbilityImpl implements Ability { } /** - * * @param game * @param source * @return @@ -883,7 +880,7 @@ public abstract class AbilityImpl implements Ability { if (!this.hasSourceObjectAbility(game, source, event)) { return false; } - if (zone.equals(Zone.COMMAND)) { + if (zone == Zone.COMMAND) { if (this.getSourceId() == null) { // commander effects return true; } @@ -1027,7 +1024,7 @@ public abstract class AbilityImpl implements Ability { sb.append("unknown"); } if (object instanceof Spell && ((Spell) object).getSpellAbilities().size() > 1) { - if (((Spell) object).getSpellAbility().getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) { + if (((Spell) object).getSpellAbility().getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) { Spell spell = (Spell) object; int i = 0; for (SpellAbility spellAbility : spell.getSpellAbilities()) { diff --git a/Mage/src/main/java/mage/abilities/common/DiesTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/DiesTriggeredAbility.java index 541ea59c6d..b587bbc7bb 100644 --- a/Mage/src/main/java/mage/abilities/common/DiesTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/DiesTriggeredAbility.java @@ -37,7 +37,6 @@ import mage.game.permanent.Permanent; import mage.game.permanent.PermanentToken; /** - * * @author BetaSteward_at_googlemail.com */ public class DiesTriggeredAbility extends ZoneChangeTriggeredAbility { @@ -69,7 +68,7 @@ public class DiesTriggeredAbility extends ZoneChangeTriggeredAbility { @Override public boolean checkEventType(GameEvent event, Game game) { if (super.checkEventType(event, game)) { - return ((ZoneChangeEvent) event).getFromZone().equals(Zone.BATTLEFIELD) && ((ZoneChangeEvent) event).getToZone().equals(Zone.GRAVEYARD); + return ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD && ((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD; } return false; } diff --git a/Mage/src/main/java/mage/abilities/common/EntersBattlefieldOrLeavesSourceTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/EntersBattlefieldOrLeavesSourceTriggeredAbility.java index 02a0a1e1fb..2ed06b5636 100644 --- a/Mage/src/main/java/mage/abilities/common/EntersBattlefieldOrLeavesSourceTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/EntersBattlefieldOrLeavesSourceTriggeredAbility.java @@ -36,7 +36,6 @@ import mage.game.events.GameEvent.EventType; import mage.game.events.ZoneChangeEvent; /** - * * @author LevelX2 */ public class EntersBattlefieldOrLeavesSourceTriggeredAbility extends TriggeredAbilityImpl { @@ -68,7 +67,7 @@ public class EntersBattlefieldOrLeavesSourceTriggeredAbility extends TriggeredAb } if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(this.getSourceId())) { ZoneChangeEvent zEvent = (ZoneChangeEvent) event; - if (zEvent.getFromZone().equals(Zone.BATTLEFIELD)) { + if (zEvent.getFromZone() == Zone.BATTLEFIELD) { return true; } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/ManaEffect.java b/Mage/src/main/java/mage/abilities/effects/common/ManaEffect.java index 1541c53114..e489056436 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/ManaEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/ManaEffect.java @@ -63,7 +63,7 @@ public abstract class ManaEffect extends OneShotEffect { * @param source */ public void checkToFirePossibleEvents(Mana mana, Game game, Ability source) { - if (source.getAbilityType().equals(AbilityType.MANA)) { + if (source.getAbilityType()==AbilityType.MANA) { for (Cost cost: source.getCosts()) { if (cost instanceof TapSourceCost) { ManaEvent event = new ManaEvent(GameEvent.EventType.TAPPED_FOR_MANA, source.getSourceId(), source.getSourceId(), source.getControllerId(), mana); diff --git a/Mage/src/main/java/mage/abilities/effects/common/PreventDamageToControllerEffect.java b/Mage/src/main/java/mage/abilities/effects/common/PreventDamageToControllerEffect.java index 3bd662416c..92ae7dcf75 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/PreventDamageToControllerEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/PreventDamageToControllerEffect.java @@ -88,7 +88,7 @@ public class PreventDamageToControllerEffect extends PreventionEffectImpl { sb.append("combat "); } sb.append("damage that would be dealt to you"); - if (duration.equals(Duration.EndOfTurn)) { + if (duration == Duration.EndOfTurn) { sb.append(" this turn"); } return sb.toString(); diff --git a/Mage/src/main/java/mage/abilities/keyword/ImproviseAbility.java b/Mage/src/main/java/mage/abilities/keyword/ImproviseAbility.java index 12ff28c861..738537f59d 100644 --- a/Mage/src/main/java/mage/abilities/keyword/ImproviseAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/ImproviseAbility.java @@ -6,6 +6,7 @@ package mage.abilities.keyword; import java.util.UUID; + import mage.Mana; import mage.abilities.Ability; import mage.abilities.SpecialAction; @@ -30,7 +31,6 @@ import mage.target.Target; import mage.target.common.TargetControlledPermanent; /** - * * @author LevelX2 */ public class ImproviseAbility extends SimpleStaticAbility implements AlternateManaPaymentAbility { @@ -59,7 +59,7 @@ public class ImproviseAbility extends SimpleStaticAbility implements AlternateMa public void addSpecialAction(Ability source, Game game, ManaCost unpaid) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null && game.getBattlefield().contains(filterUntapped, controller.getId(), 1, game)) { - if (source.getAbilityType().equals(AbilityType.SPELL) && unpaid.getMana().getGeneric() > 0) { + if (source.getAbilityType() == AbilityType.SPELL && unpaid.getMana().getGeneric() > 0) { SpecialAction specialAction = new ImproviseSpecialAction(unpaid); specialAction.setControllerId(source.getControllerId()); specialAction.setSourceId(source.getSourceId()); diff --git a/Mage/src/main/java/mage/game/turn/Phase.java b/Mage/src/main/java/mage/game/turn/Phase.java index 4d2d1a0d33..e4b276336e 100644 --- a/Mage/src/main/java/mage/game/turn/Phase.java +++ b/Mage/src/main/java/mage/game/turn/Phase.java @@ -107,7 +107,7 @@ public abstract class Phase implements Serializable { if (game.isPaused() || game.gameOver(null)) { return false; } - if (game.getTurn().isEndTurnRequested() && !step.getType().equals(PhaseStep.CLEANUP)) { + if (game.getTurn().isEndTurnRequested() && step.getType()!=PhaseStep.CLEANUP) { continue; } currentStep = step; diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index fc5357dc51..f28a652e54 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -27,55 +27,20 @@ */ package mage.players; -import java.io.Serializable; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.UUID; import mage.ConditionalMana; import mage.MageObject; import mage.Mana; -import mage.abilities.Abilities; -import mage.abilities.AbilitiesImpl; -import mage.abilities.Ability; -import mage.abilities.ActivatedAbility; -import mage.abilities.DelayedTriggeredAbility; -import mage.abilities.Mode; -import mage.abilities.PlayLandAbility; -import mage.abilities.SpecialAction; -import mage.abilities.SpellAbility; -import mage.abilities.TriggeredAbility; +import mage.abilities.*; import mage.abilities.common.PassAbility; import mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility; -import mage.abilities.costs.AdjustingSourceCosts; -import mage.abilities.costs.AlternativeCostSourceAbility; -import mage.abilities.costs.AlternativeSourceCosts; -import mage.abilities.costs.Cost; -import mage.abilities.costs.Costs; -import mage.abilities.costs.OptionalAdditionalSourceCosts; +import mage.abilities.costs.*; import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCosts; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.RestrictionUntapNotMoreThanEffect; import mage.abilities.effects.common.LoseControlOnOtherPlayersControllerEffect; -import mage.abilities.keyword.ConvokeAbility; -import mage.abilities.keyword.FlashbackAbility; -import mage.abilities.keyword.HexproofAbility; -import mage.abilities.keyword.InfectAbility; -import mage.abilities.keyword.LifelinkAbility; -import mage.abilities.keyword.ProtectionAbility; -import mage.abilities.keyword.ShroudAbility; +import mage.abilities.keyword.*; import mage.abilities.mana.ActivatedManaAbilityImpl; import mage.abilities.mana.ManaOptions; import mage.actions.MageDrawAction; @@ -84,17 +49,7 @@ import mage.cards.Cards; import mage.cards.CardsImpl; import mage.cards.SplitCard; import mage.cards.decks.Deck; -import mage.constants.AbilityType; -import mage.constants.AsThoughEffectType; -import mage.constants.CardType; -import mage.constants.ManaType; -import mage.constants.Outcome; -import mage.constants.PhaseStep; -import mage.constants.PlayerAction; -import mage.constants.RangeOfInfluence; -import mage.constants.SpellAbilityType; -import mage.constants.TimingRule; -import mage.constants.Zone; +import mage.constants.*; import mage.counters.Counter; import mage.counters.CounterType; import mage.counters.Counters; @@ -105,12 +60,7 @@ import mage.filter.common.FilterCreatureForCombat; import mage.filter.common.FilterCreatureForCombatBlock; import mage.filter.predicate.Predicates; import mage.filter.predicate.permanent.PermanentIdPredicate; -import mage.game.ExileZone; -import mage.game.Game; -import mage.game.Graveyard; -import mage.game.Table; -import mage.game.ZoneChangeInfo; -import mage.game.ZonesHandler; +import mage.game.*; import mage.game.combat.CombatGroup; import mage.game.command.CommandObject; import mage.game.events.DamagePlayerEvent; @@ -137,6 +87,11 @@ import mage.util.GameLog; import mage.util.RandomUtil; import org.apache.log4j.Logger; +import java.io.Serializable; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.Map.Entry; + public abstract class PlayerImpl implements Player, Serializable { private static final Logger logger = Logger.getLogger(PlayerImpl.class); @@ -472,7 +427,6 @@ public abstract class PlayerImpl implements Player, Serializable { /** * called before apply effects - * */ @Override public void reset() { @@ -701,7 +655,6 @@ public abstract class PlayerImpl implements Player, Serializable { } /** - * * @param amount * @param source * @param game @@ -998,7 +951,7 @@ public abstract class PlayerImpl implements Player, Serializable { if (game == null || ability == null) { return false; } - if (!ability.getSpellAbilityType().equals(SpellAbilityType.BASE)) { + if (ability.getSpellAbilityType() != SpellAbilityType.BASE) { ability = chooseSpellAbilityForCast(ability, game, noMana); } //20091005 - 601.2a @@ -1221,7 +1174,7 @@ public abstract class PlayerImpl implements Player, Serializable { //if player has taken an action then reset all player passed flags justActivatedType = null; if (result) { - if (isHuman() && (ability.getAbilityType().equals(AbilityType.SPELL) || ability.getAbilityType().equals(AbilityType.ACTIVATED))) { + if (isHuman() && (ability.getAbilityType() == AbilityType.SPELL || ability.getAbilityType() == AbilityType.ACTIVATED)) { if (ability.isUsesStack()) { // if the ability does not use the stack (e.g. Suspend) auto pass would go to next phase unintended setJustActivatedType(ability.getAbilityType()); } @@ -1269,8 +1222,8 @@ public abstract class PlayerImpl implements Player, Serializable { LinkedHashMap useable = new LinkedHashMap<>(); for (Ability ability : object.getAbilities()) { if (ability instanceof SpellAbility) { - if (((SpellAbility) ability).getSpellAbilityType().equals(SpellAbilityType.SPLIT_FUSED)) { - if (zone.equals(Zone.HAND)) { + if (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) { + if (zone == Zone.HAND) { // Fix so you don't need to choose Fuse twice useable.clear(); useable.put(ability.getId(), (SpellAbility) ability); @@ -1280,7 +1233,7 @@ public abstract class PlayerImpl implements Player, Serializable { continue; } } - if (((SpellAbility) ability).getSpellAbilityType().equals(SpellAbilityType.SPLIT)) { + if (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.SPLIT) { continue; } useable.put(ability.getId(), (SpellAbility) ability); @@ -1297,7 +1250,7 @@ public abstract class PlayerImpl implements Player, Serializable { // ManaOptions availableMana = getManaAvailable(game); // can only be activated if mana calculation works flawless otherwise player can't play spells they could play if calculation would work correctly // availableMana.addMana(manaPool.getMana()); for (Ability ability : object.getAbilities()) { - if (canUse || ability.getAbilityType().equals(AbilityType.SPECIAL_ACTION)) { + if (canUse || ability.getAbilityType() == AbilityType.SPECIAL_ACTION) { if (ability.getZone().match(zone)) { if (ability instanceof ActivatedAbility) { if (ability instanceof ActivatedManaAbilityImpl) { @@ -1320,9 +1273,9 @@ public abstract class PlayerImpl implements Player, Serializable { } } if (zone != Zone.HAND) { - if (Zone.GRAVEYARD.equals(zone) && canPlayCardsFromGraveyard()) { + if (Zone.GRAVEYARD == zone && canPlayCardsFromGraveyard()) { for (ActivatedAbility ability : object.getAbilities().getPlayableAbilities(Zone.HAND)) { - if (canUse || ability.getAbilityType().equals(AbilityType.SPECIAL_ACTION)) { + if (canUse || ability.getAbilityType() == AbilityType.SPECIAL_ACTION) { if (ability.getManaCosts().isEmpty() && ability.getCosts().isEmpty() && ability instanceof SpellAbility) { continue; // You can't play spells from graveyard that have no costs } @@ -1334,7 +1287,7 @@ public abstract class PlayerImpl implements Player, Serializable { } if (zone != Zone.BATTLEFIELD && game.getContinuousEffects().asThough(object.getId(), AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, this.getId(), game)) { for (Ability ability : object.getAbilities()) { - if (canUse || ability.getAbilityType().equals(AbilityType.SPECIAL_ACTION)) { + if (canUse || ability.getAbilityType() == AbilityType.SPECIAL_ACTION) { if (ability.getManaCosts().isEmpty() && ability.getCosts().isEmpty() && ability instanceof SpellAbility && !(ability.getSourceId() == getCastSourceIdWithAlternateMana())) { continue; // You can't play spells that have no costs, unless you can play them without paying their mana costs } @@ -1358,7 +1311,7 @@ public abstract class PlayerImpl implements Player, Serializable { if (otherAbilities != null) { boolean canUse = !(object instanceof Permanent) || ((Permanent) object).canUseActivatedAbilities(game); for (ActivatedAbility ability : otherAbilities) { - if (canUse || ability.getAbilityType().equals(AbilityType.SPECIAL_ACTION)) { + if (canUse || ability.getAbilityType() == AbilityType.SPECIAL_ACTION) { Card card = game.getCard(ability.getSourceId()); if (card.isSplitCard() && ability instanceof FlashbackAbility) { FlashbackAbility flashbackAbility; @@ -1401,7 +1354,7 @@ public abstract class PlayerImpl implements Player, Serializable { LinkedHashMap useable = new LinkedHashMap<>(); boolean canUse = !(object instanceof Permanent) || ((Permanent) object).canUseActivatedAbilities(game); for (ActivatedManaAbilityImpl ability : object.getAbilities().getActivatedManaAbilities(zone)) { - if (canUse || ability.getAbilityType().equals(AbilityType.SPECIAL_ACTION)) { + if (canUse || ability.getAbilityType() == AbilityType.SPECIAL_ACTION) { if (ability.canActivate(playerId, game)) { useable.put(ability.getId(), ability); } @@ -2057,7 +2010,7 @@ public abstract class PlayerImpl implements Player, Serializable { passedUntilEndOfTurn = true; passedUntilStackResolved = false; passedUntilEndStepBeforeMyTurn = false; - skippedAtLeastOnce = !PhaseStep.END_TURN.equals(game.getTurn().getStepType()); + skippedAtLeastOnce = PhaseStep.END_TURN != game.getTurn().getStepType(); this.skip(); break; case PASS_PRIORITY_UNTIL_NEXT_TURN: // F4 @@ -2088,7 +2041,7 @@ public abstract class PlayerImpl implements Player, Serializable { passedUntilNextMain = true; passedUntilStackResolved = false; passedUntilEndStepBeforeMyTurn = false; - skippedAtLeastOnce = !(game.getTurn().getStepType().equals(PhaseStep.POSTCOMBAT_MAIN) || game.getTurn().getStepType().equals(PhaseStep.PRECOMBAT_MAIN)); + skippedAtLeastOnce = !(game.getTurn().getStepType() == PhaseStep.POSTCOMBAT_MAIN || game.getTurn().getStepType() == PhaseStep.PRECOMBAT_MAIN); this.skip(); break; case PASS_PRIORITY_UNTIL_STACK_RESOLVED: //F8 @@ -2333,7 +2286,6 @@ public abstract class PlayerImpl implements Player, Serializable { /** * @param game * @param appliedEffects - * * @return true if player won the toss */ @Override @@ -2470,9 +2422,8 @@ public abstract class PlayerImpl implements Player, Serializable { } /** - * * @param ability - * @param available if null, it won't be checked if enough mana is available + * @param available if null, it won't be checked if enough mana is available * @param sourceObject * @param game * @return @@ -2608,7 +2559,7 @@ public abstract class PlayerImpl implements Player, Serializable { if (!(sourceObject instanceof Permanent)) { Ability sourceAbility = null; for (Ability landAbility : sourceObject.getAbilities()) { - if (landAbility.getAbilityType().equals(AbilityType.PLAY_LAND)) { + if (landAbility.getAbilityType() == AbilityType.PLAY_LAND) { sourceAbility = landAbility; break; } @@ -2779,10 +2730,8 @@ public abstract class PlayerImpl implements Player, Serializable { * Creates a list of card ids that are currently playable.
* Used to mark the playable cards in GameView * - * @return A Set of cardIds that are playable - * * @param game - * + * @return A Set of cardIds that are playable */ @Override public Set getPlayableInHand(Game game @@ -3189,8 +3138,8 @@ public abstract class PlayerImpl implements Player, Serializable { case HAND: for (Card card : cards) { fromZone = game.getState().getZone(card.getId()); - boolean hideCard = fromZone.equals(Zone.LIBRARY) - || (card.isFaceDown(game) && !fromZone.equals(Zone.STACK) && !fromZone.equals(Zone.BATTLEFIELD)); + boolean hideCard = fromZone == Zone.LIBRARY + || (card.isFaceDown(game) && fromZone != Zone.STACK && fromZone != Zone.BATTLEFIELD); if (moveCardToHandWithInfo(card, source == null ? null : source.getSourceId(), game, !hideCard)) { successfulMovedCards.add(card); } @@ -3199,7 +3148,7 @@ public abstract class PlayerImpl implements Player, Serializable { case EXILED: for (Card card : cards) { fromZone = game.getState().getZone(card.getId()); - boolean withName = (fromZone.equals(Zone.BATTLEFIELD) || fromZone.equals(Zone.STACK)) || !card.isFaceDown(game); + boolean withName = (fromZone == Zone.BATTLEFIELD || fromZone == Zone.STACK) || !card.isFaceDown(game); if (moveCardToExileWithInfo(card, null, "", source == null ? null : source.getSourceId(), game, fromZone, withName)) { successfulMovedCards.add(card); } @@ -3212,7 +3161,7 @@ public abstract class PlayerImpl implements Player, Serializable { } else { fromZone = game.getState().getZone(card.getId()); } - boolean hideCard = fromZone.equals(Zone.HAND) || fromZone.equals(Zone.LIBRARY); + boolean hideCard = fromZone == Zone.HAND || fromZone == Zone.LIBRARY; if (moveCardToLibraryWithInfo(card, source == null ? null : source.getSourceId(), game, fromZone, true, !hideCard)) { successfulMovedCards.add(card); } @@ -3253,7 +3202,7 @@ public abstract class PlayerImpl implements Player, Serializable { public boolean moveCardToHandWithInfo(Card card, UUID sourceId, Game game, boolean withName) { boolean result = false; Zone fromZone = game.getState().getZone(card.getId()); - if (fromZone.equals(Zone.BATTLEFIELD) && !(card instanceof Permanent)) { + if (fromZone == Zone.BATTLEFIELD && !(card instanceof Permanent)) { card = game.getPermanent(card.getId()); } if (card.moveToZone(Zone.HAND, sourceId, game, false)) { @@ -3280,7 +3229,7 @@ public abstract class PlayerImpl implements Player, Serializable { // identify cards from one owner Cards cards = new CardsImpl(); UUID ownerId = null; - for (Iterator it = allCards.iterator(); it.hasNext();) { + for (Iterator it = allCards.iterator(); it.hasNext(); ) { Card card = it.next(); if (cards.isEmpty()) { ownerId = card.getOwnerId(); @@ -3343,7 +3292,7 @@ public abstract class PlayerImpl implements Player, Serializable { public boolean moveCardToGraveyardWithInfo(Card card, UUID sourceId, Game game, Zone fromZone) { boolean result = false; // Zone fromZone = game.getState().getZone(card.getId()); - if (card.moveToZone(Zone.GRAVEYARD, sourceId, game, fromZone != null ? fromZone.equals(Zone.BATTLEFIELD) : false)) { + if (card.moveToZone(Zone.GRAVEYARD, sourceId, game, fromZone != null ? fromZone == Zone.BATTLEFIELD : false)) { if (!game.isSimulation()) { if (card instanceof PermanentCard && game.getCard(card.getId()) != null) { card = game.getCard(card.getId()); diff --git a/Mage/src/main/java/mage/target/TargetImpl.java b/Mage/src/main/java/mage/target/TargetImpl.java index 4e6f9cc4c7..0bd012dd1b 100644 --- a/Mage/src/main/java/mage/target/TargetImpl.java +++ b/Mage/src/main/java/mage/target/TargetImpl.java @@ -36,6 +36,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; + import mage.MageObject; import mage.abilities.Ability; import mage.cards.Card; @@ -49,7 +50,6 @@ import mage.players.Player; import mage.util.RandomUtil; /** - * * @author BetaSteward_at_googlemail.com */ public abstract class TargetImpl implements Target { @@ -184,7 +184,7 @@ public abstract class TargetImpl implements Target { @Override public boolean isRequired(Ability ability) { - return ability == null || ability.isActivated() || !(ability.getAbilityType().equals(AbilityType.SPELL) || ability.getAbilityType().equals(AbilityType.ACTIVATED)); + return ability == null || ability.isActivated() || !(ability.getAbilityType() == AbilityType.SPELL || ability.getAbilityType() == AbilityType.ACTIVATED); } @Override diff --git a/Mage/src/main/java/mage/watchers/common/CardsPutIntoGraveyardWatcher.java b/Mage/src/main/java/mage/watchers/common/CardsPutIntoGraveyardWatcher.java index f89306278e..4fbf9765f6 100644 --- a/Mage/src/main/java/mage/watchers/common/CardsPutIntoGraveyardWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/CardsPutIntoGraveyardWatcher.java @@ -33,6 +33,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.UUID; + import mage.MageObjectReference; import mage.constants.WatcherScope; import mage.constants.Zone; @@ -80,7 +81,7 @@ public class CardsPutIntoGraveyardWatcher extends Watcher { ++amount; } amountOfCardsThisTurn.put(playerId, amount); - if (((ZoneChangeEvent) event).getFromZone().equals(Zone.BATTLEFIELD)) { + if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) { cardsPutToGraveyardFromBattlefield.add(new MageObjectReference(event.getTargetId(), game)); } }