From 3359c1f3f1882068e13b273ede8ae24b4524399e Mon Sep 17 00:00:00 2001 From: Ingmar Goudt Date: Fri, 22 Feb 2019 12:05:44 +0100 Subject: [PATCH] sonar 220219, criticals --- .../java/mage/client/cards/DragCardGrid.java | 2 +- .../java/mage/client/chat/LocalCommands.java | 3 + .../mage/client/components/MageRoundPane.java | 6 +- .../components/ability/BackgroundPainter.java | 4 +- .../components/ext/MessageDialogType.java | 8 + .../client/components/ext/MessageDlg.java | 13 -- .../components/ext/dlg/DialogContainer.java | 207 +++++++----------- .../components/ext/dlg/DialogManager.java | 19 +- .../client/components/ext/dlg/DlgParams.java | 14 +- .../mage/client/unusedFiles/CombatDialog.java | 4 +- .../src/main/java/mage/utils/DeckBuilder.java | 14 +- .../server/record/TableRecordRepository.java | 3 +- .../server/record/UserStatsRepository.java | 7 +- .../main/java/mage/server/util/Config.java | 2 + .../mage/server/util/ServerMessagesUtil.java | 16 +- .../main/java/mage/server/util/Splitter.java | 2 + .../java/mage/server/util/SystemUtil.java | 15 +- Mage.Sets/src/mage/cards/a/Antagonism.java | 4 +- Mage.Sets/src/mage/cards/n/NullChamber.java | 72 ------ Mage.Sets/src/mage/cards/v/VenarianGold.java | 2 +- Mage.Sets/src/mage/cards/w/WallOfShadows.java | 2 +- .../common/SkipNextDrawStepTargetEffect.java | 2 +- .../mage/abilities/keyword/BountyAbility.java | 12 +- 23 files changed, 153 insertions(+), 280 deletions(-) create mode 100644 Mage.Client/src/main/java/mage/client/components/ext/MessageDialogType.java delete mode 100644 Mage.Client/src/main/java/mage/client/components/ext/MessageDlg.java diff --git a/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java b/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java index 6364c83f9b..12ca7ef2f7 100644 --- a/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java +++ b/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java @@ -805,7 +805,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg insertArrow = new JLabel(); insertArrow.setSize(20, 20); insertArrow.setVisible(false); - cardContent.add(insertArrow, new Integer(1000)); + cardContent.add(insertArrow, 1000); // Selection panel selectionPanel = new SelectionBox(); diff --git a/Mage.Client/src/main/java/mage/client/chat/LocalCommands.java b/Mage.Client/src/main/java/mage/client/chat/LocalCommands.java index 92731f941c..2fd0878f8f 100644 --- a/Mage.Client/src/main/java/mage/client/chat/LocalCommands.java +++ b/Mage.Client/src/main/java/mage/client/chat/LocalCommands.java @@ -14,6 +14,9 @@ import java.util.UUID; public final class LocalCommands { + + private LocalCommands(){} + /** * Handler for commands that do not require server interaction, i.e settings etc * @param chatId diff --git a/Mage.Client/src/main/java/mage/client/components/MageRoundPane.java b/Mage.Client/src/main/java/mage/client/components/MageRoundPane.java index 7d5e2c1fd0..7f7a774562 100644 --- a/Mage.Client/src/main/java/mage/client/components/MageRoundPane.java +++ b/Mage.Client/src/main/java/mage/client/components/MageRoundPane.java @@ -26,7 +26,7 @@ public class MageRoundPane extends JPanel { private int Y_OFFSET = 30; private final Color defaultBackgroundColor = new Color(141, 130, 112, 200); // color of the frame of the popup window private Color backgroundColor = defaultBackgroundColor; - private static final int alpha = 0; + private static final int ALPHA = 0; private static final Map SHADOW_IMAGE_CACHE; private static final Map IMAGE_CACHE; @@ -163,8 +163,8 @@ public class MageRoundPane extends JPanel { /** * Add white translucent substrate */ - /*if (alpha != 0) { - g2.setColor(new Color(255, 255, 255, alpha)); + /*if (ALPHA != 0) { + g2.setColor(new Color(255, 255, 255, ALPHA)); g2.fillRoundRect(x, y, w, h, arc, arc); }*/ g2.setColor(key.backgroundColor); diff --git a/Mage.Client/src/main/java/mage/client/components/ability/BackgroundPainter.java b/Mage.Client/src/main/java/mage/client/components/ability/BackgroundPainter.java index d87f2c7057..9a2f806913 100644 --- a/Mage.Client/src/main/java/mage/client/components/ability/BackgroundPainter.java +++ b/Mage.Client/src/main/java/mage/client/components/ability/BackgroundPainter.java @@ -16,7 +16,7 @@ public class BackgroundPainter extends AbstractPainter { private final Color bgColor = Color.black; - static final float bgalpha = 0.6f; + static final float BACKGROUND_ALPHA = 0.6f; public BackgroundPainter() { super(); @@ -25,7 +25,7 @@ public class BackgroundPainter extends AbstractPainter { @Override protected void doPaint(Graphics2D g2, Object o, int i, int i1) { - float alpha = bgalpha; + float alpha = BACKGROUND_ALPHA; Component c = (Component)o; Composite composite = g2.getComposite(); if (composite instanceof AlphaComposite) { diff --git a/Mage.Client/src/main/java/mage/client/components/ext/MessageDialogType.java b/Mage.Client/src/main/java/mage/client/components/ext/MessageDialogType.java new file mode 100644 index 0000000000..535355a85a --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/components/ext/MessageDialogType.java @@ -0,0 +1,8 @@ +package mage.client.components.ext; + +public enum MessageDialogType { + INFO, + WARNING, + ERROR, + FLASH_INFO +} diff --git a/Mage.Client/src/main/java/mage/client/components/ext/MessageDlg.java b/Mage.Client/src/main/java/mage/client/components/ext/MessageDlg.java deleted file mode 100644 index a09b8ca796..0000000000 --- a/Mage.Client/src/main/java/mage/client/components/ext/MessageDlg.java +++ /dev/null @@ -1,13 +0,0 @@ -package mage.client.components.ext; - -/** - * @author mw, noxx - */ -public class MessageDlg { - - MessageDlg() {} - - public enum Types { - Info, Warning, Error, FlashInfo - } -} \ No newline at end of file diff --git a/Mage.Client/src/main/java/mage/client/components/ext/dlg/DialogContainer.java b/Mage.Client/src/main/java/mage/client/components/ext/dlg/DialogContainer.java index 39845bae64..81048c967c 100644 --- a/Mage.Client/src/main/java/mage/client/components/ext/dlg/DialogContainer.java +++ b/Mage.Client/src/main/java/mage/client/components/ext/dlg/DialogContainer.java @@ -1,6 +1,6 @@ package mage.client.components.ext.dlg; -import mage.client.components.ext.MessageDlg; +import mage.client.components.ext.MessageDialogType; import mage.client.components.ext.dlg.impl.ChoiceDialog; import mage.client.components.ext.dlg.impl.StackDialog; @@ -37,146 +37,99 @@ public class DialogContainer extends JPanel { setLayout(null); drawContainer = true; - if (dialogType == DialogManager.MTGDialogs.MessageDialog) { - //backgroundColor = new Color(0, 255, 255, 60); - if (params.type == MessageDlg.Types.Warning) { - backgroundColor = new Color(255, 0, 0, 90); - } else { - backgroundColor = new Color(0, 0, 0, 90); + switch (dialogType) { + case MESSAGE: + //backgroundColor = new Color(0, 255, 255, 60); + if (params.type == MessageDialogType.WARNING) { + backgroundColor = new Color(255, 0, 0, 90); + } else { + backgroundColor = new Color(0, 0, 0, 90); + } + alpha = 0; + //MessageDlg dlg = new MessageDlg(params); + //add(dlg); + //dlg.setLocation(X_OFFSET + 10, Y_OFFSET); + //dlg.updateSize(params.rect.width, params.rect.height); + break; + case STACK: { + //backgroundColor = new Color(0, 255, 255, 60); + backgroundColor = new Color(0, 0, 0, 50); + alpha = 0; + StackDialog dlg = new StackDialog(params); + add(dlg); + dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); + //int width = Math.min(params.rect.width - 80, 600); + int width = params.rect.width; + int height = params.rect.height - 80; + dlg.updateSize(width, height); + break; } - alpha = 0; - //MessageDlg dlg = new MessageDlg(params); - //add(dlg); - //dlg.setLocation(X_OFFSET + 10, Y_OFFSET); - //dlg.updateSize(params.rect.width, params.rect.height); - } else if (dialogType == DialogManager.MTGDialogs.StackDialog) { - //backgroundColor = new Color(0, 255, 255, 60); - backgroundColor = new Color(0, 0, 0, 50); - alpha = 0; - StackDialog dlg = new StackDialog(params); - add(dlg); - dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); - //int width = Math.min(params.rect.width - 80, 600); - int width = params.rect.width; - int height = params.rect.height - 80; - dlg.updateSize(width, height); - } /* - else if (dialogType == DialogManager.MTGDialogs.CombatDialog) { + else if (dialogType == DialogManager.MTGDialogs.COMBAT) { backgroundColor = new Color(0, 0, 0, 60); alpha = 0; - CombatDialog dlg = new CombatDialog(params); + COMBAT dlg = new COMBAT(params); add(dlg); dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); dlg.updateSize(params.rect.width - 80, params.rect.height - 80); - }*/ else if (dialogType == DialogManager.MTGDialogs.ChoiceDialog) { + }*/ + case CHOICE: { - //backgroundColor = new Color(200, 200, 172, 120); - //backgroundColor = new Color(180, 150, 200, 120); - //backgroundColor = new Color(0, 255, 0, 60); + //backgroundColor = new Color(200, 200, 172, 120); + //backgroundColor = new Color(180, 150, 200, 120); + //backgroundColor = new Color(0, 255, 0, 60); - //backgroundColor = new Color(139, 46, 173, 20); - backgroundColor = new Color(0, 0, 0, 110); - //backgroundColor = new Color(139, 46, 173, 0); + //backgroundColor = new Color(139, 46, 173, 20); + backgroundColor = new Color(0, 0, 0, 110); + //backgroundColor = new Color(139, 46, 173, 0); - alpha = 0; - ChoiceDialog dlg = new ChoiceDialog(params, "Choose"); - add(dlg); - //GameManager.getManager().setCurrentChoiceDlg(dlg); - dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); - dlg.updateSize(params.rect.width - 80, params.rect.height - 80); + alpha = 0; + ChoiceDialog dlg = new ChoiceDialog(params, "Choose"); + add(dlg); + //GameManager.getManager().setCurrentChoiceDlg(dlg); + dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); + dlg.updateSize(params.rect.width - 80, params.rect.height - 80); - } else if (dialogType == DialogManager.MTGDialogs.GraveDialog) { - - backgroundColor = new Color(0, 0, 0, 110); - - alpha = 0; - ChoiceDialog dlg = new ChoiceDialog(params, "Graveyard"); - add(dlg); - dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); - dlg.updateSize(params.rect.width - 80, params.rect.height - 80); - - } else if (dialogType == DialogManager.MTGDialogs.ExileDialog) { - - backgroundColor = new Color(250, 250, 250, 50); - - alpha = 0; - ChoiceDialog dlg = new ChoiceDialog(params, "Exile"); - add(dlg); - dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); - dlg.updateSize(params.rect.width - 80, params.rect.height - 80); - - } else if (dialogType == DialogManager.MTGDialogs.EmblemsDialog) { - - backgroundColor = new Color(0, 0, 50, 110); - - alpha = 0; - ChoiceDialog dlg = new ChoiceDialog(params, "Command Zone (Commander, Emblems and Planes)"); - add(dlg); - dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); - dlg.updateSize(params.rect.width - 80, params.rect.height - 80); - - } /*else if (dialogType == DialogManager.MTGDialogs.GraveDialog) { - backgroundColor = new Color(20, 20, 20, 120); - alpha = 0; - GraveDialog dlg = new GraveDialog(params); - add(dlg); - dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); - dlg.updateSize(params.rect.width - 80, params.rect.height - 80); - - } else if (dialogType == DialogManager.MTGDialogs.RevealDialog) { - backgroundColor = new Color(90, 135, 190, 80); - alpha = 0; - RevealDialog dlg = new RevealDialog(params); - add(dlg); - dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); - dlg.updateSize(params.rect.width - 80, params.rect.height - 80); - - } else if (dialogType == DialogManager.MTGDialogs.AssignDamageDialog) { - backgroundColor = new Color(255, 255, 255, 130); - alpha = 0; - AssignDamageDialog dlg = new AssignDamageDialog(params); - add(dlg); - dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); - dlg.updateSize(params.rect.width - 80, params.rect.height - 80); - } else if (dialogType == DialogManager.MTGDialogs.ManaChoiceDialog) { - backgroundColor = new Color(0, 255, 255, 60); - alpha = 20; - ManaChoiceDialog dlg = new ManaChoiceDialog(params); - add(dlg); - dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); - dlg.updateSize(params.rect.width - 80, params.rect.height - 80); - - //isGradient = true; - gradient = ImageManager.getGradientImage(); - if (gradient != null) { - b = ImageToBufferedImage.toBufferedImage(gradient); - b = Transparency.makeImageTranslucent(b, 0.35); - Rectangle2D tr = new Rectangle2D.Double(0, 0, params.rect.width, params.rect.height); - //gradient = gradient.getScaledInstance(w, h, Image.SCALE_SMOOTH); - tp = new TexturePaint(b, tr); + break; + } + case GRAVEYARD: { + + backgroundColor = new Color(0, 0, 0, 110); + + alpha = 0; + ChoiceDialog dlg = new ChoiceDialog(params, "Graveyard"); + add(dlg); + dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); + dlg.updateSize(params.rect.width - 80, params.rect.height - 80); + + break; + } + case EXILE: { + + backgroundColor = new Color(250, 250, 250, 50); + + alpha = 0; + ChoiceDialog dlg = new ChoiceDialog(params, "Exile"); + add(dlg); + dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); + dlg.updateSize(params.rect.width - 80, params.rect.height - 80); + + break; + } + case EMBLEMS: { + + backgroundColor = new Color(0, 0, 50, 110); + + alpha = 0; + ChoiceDialog dlg = new ChoiceDialog(params, "Command Zone (Commander, Emblems and Planes)"); + add(dlg); + dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); + dlg.updateSize(params.rect.width - 80, params.rect.height - 80); + + break; } - } else if (dialogType == DialogManager.MTGDialogs.ChooseDeckDialog) { - MWDeckPanel deckPanel = new MWDeckPanel(params.getDeckList(), params.isAI); - deckPanel.setVisible(true); - deckPanel.setBounds(0,0,480,320); - add(deckPanel); - drawContainer = false; - } else if (dialogType == DialogManager.MTGDialogs.ChooseCommonDialog) { - MWChoosePanel choosePanel = new MWChoosePanel(params.getObjectList(), params.getTitle()); - choosePanel.setVisible(true); - choosePanel.setBounds(0,0,440,240); - add(choosePanel); - drawContainer = false; - } else if (dialogType == DialogManager.MTGDialogs.AboutDialog) { - backgroundColor = new Color(255, 255, 255, 120); - alpha = 0; - AboutDialog dlg = new AboutDialog(); - add(dlg); - dlg.setLocation(X_OFFSET + 10, Y_OFFSET + 10); } - */ } public void cleanUp() { diff --git a/Mage.Client/src/main/java/mage/client/components/ext/dlg/DialogManager.java b/Mage.Client/src/main/java/mage/client/components/ext/dlg/DialogManager.java index 89cf45f1c1..6b1e3a82c0 100644 --- a/Mage.Client/src/main/java/mage/client/components/ext/dlg/DialogManager.java +++ b/Mage.Client/src/main/java/mage/client/components/ext/dlg/DialogManager.java @@ -39,8 +39,8 @@ public class DialogManager extends JComponent implements MouseListener, } public enum MTGDialogs { - none, AboutDialog, MessageDialog, StackDialog, AssignDamageDialog, ManaChoiceDialog, ChoiceDialog, EmblemsDialog, GraveDialog, DialogContainer, CombatDialog, - ChooseDeckDialog, ChooseCommonDialog, RevealDialog, ExileDialog + NONE, ABOUT, MESSAGE, STACK, ASSIGN_DAMAGE, MANA_CHOICE, CHOICE, EMBLEMS, GRAVEYARD, DialogContainer, COMBAT, + CHOOSE_DECK, CHOOSE_COMMON, REVEAL, EXILE } /** @@ -58,7 +58,7 @@ public class DialogManager extends JComponent implements MouseListener, } } - private MTGDialogs currentDialog = MTGDialogs.none; + private MTGDialogs currentDialog = MTGDialogs.NONE; private DialogContainer dialogContainer = null; @@ -133,7 +133,7 @@ public class DialogManager extends JComponent implements MouseListener, params.gameId = gameId; params.feedbackPanel = feedbackPanel; params.setCards(cards); - dialogContainer = new DialogContainer(MTGDialogs.StackDialog, params); + dialogContainer = new DialogContainer(MTGDialogs.STACK, params); dialogContainer.setVisible(true); add(dialogContainer); @@ -163,7 +163,7 @@ public class DialogManager extends JComponent implements MouseListener, params.gameId = gameId; //params.feedbackPanel = feedbackPanel; params.setCards(cards); - dialogContainer = new DialogContainer(MTGDialogs.GraveDialog, params); + dialogContainer = new DialogContainer(MTGDialogs.GRAVEYARD, params); dialogContainer.setVisible(true); add(dialogContainer); @@ -192,7 +192,7 @@ public class DialogManager extends JComponent implements MouseListener, params.bigCard = bigCard; params.gameId = gameId; params.setCards(cards); - dialogContainer = new DialogContainer(MTGDialogs.ExileDialog, params); + dialogContainer = new DialogContainer(MTGDialogs.EXILE, params); dialogContainer.setVisible(true); add(dialogContainer); @@ -222,7 +222,7 @@ public class DialogManager extends JComponent implements MouseListener, params.gameId = gameId; //params.feedbackPanel = feedbackPanel; params.setCards(cards); - dialogContainer = new DialogContainer(MTGDialogs.EmblemsDialog, params); + dialogContainer = new DialogContainer(MTGDialogs.EMBLEMS, params); dialogContainer.setVisible(true); add(dialogContainer); @@ -248,7 +248,7 @@ public class DialogManager extends JComponent implements MouseListener, removeAll(); } - this.currentDialog = MTGDialogs.none; + this.currentDialog = MTGDialogs.NONE; setVisible(false); @@ -312,6 +312,7 @@ public class DialogManager extends JComponent implements MouseListener, @Override public void mouseExited(MouseEvent e) { + } @Override @@ -360,7 +361,7 @@ public class DialogManager extends JComponent implements MouseListener, public void mouseWheelMoved(MouseWheelEvent e) { int notches = e.getWheelRotation(); // System.out.println("outx:"+notches); -// if (currentDialog != null && currentDialog.equals(MTGDialogs.ChooseCommonDialog)) { +// if (currentDialog != null && currentDialog.equals(MTGDialogs.CHOOSE_COMMON)) { // System.out.println("out:"+1); // } } diff --git a/Mage.Client/src/main/java/mage/client/components/ext/dlg/DlgParams.java b/Mage.Client/src/main/java/mage/client/components/ext/dlg/DlgParams.java index f4ad229f93..51dc575b29 100644 --- a/Mage.Client/src/main/java/mage/client/components/ext/dlg/DlgParams.java +++ b/Mage.Client/src/main/java/mage/client/components/ext/dlg/DlgParams.java @@ -1,7 +1,7 @@ package mage.client.components.ext.dlg; import mage.client.cards.BigCard; -import mage.client.components.ext.MessageDlg; +import mage.client.components.ext.MessageDialogType; import mage.client.game.FeedbackPanel; import mage.view.CardsView; @@ -19,7 +19,7 @@ import java.util.UUID; public class DlgParams { public Rectangle rect; - public MessageDlg.Types type; + public MessageDialogType type; public BigCard bigCard; public FeedbackPanel feedbackPanel; public UUID gameId; @@ -33,13 +33,13 @@ public class DlgParams { private String title; private int opponentID; - boolean isOptional = false; - boolean isChooseAbility = false; - boolean isCancelStopsPlaying = true; + private boolean isOptional = false; + private boolean isChooseAbility = false; + private boolean isCancelStopsPlaying = true; - boolean isAI = false; + private boolean isAI = false; - public Set manaChoices = new HashSet<>(); + private Set manaChoices = new HashSet<>(); public int getPlayerID() { return playerID; diff --git a/Mage.Client/src/main/java/mage/client/unusedFiles/CombatDialog.java b/Mage.Client/src/main/java/mage/client/unusedFiles/CombatDialog.java index c1f7d8df52..f3f8e826a4 100644 --- a/Mage.Client/src/main/java/mage/client/unusedFiles/CombatDialog.java +++ b/Mage.Client/src/main/java/mage/client/unusedFiles/CombatDialog.java @@ -1,7 +1,7 @@ /* - * CombatDialog.java + * COMBAT.java * * Created on Feb 10, 2010, 3:35:02 PM */ @@ -33,7 +33,7 @@ public class CombatDialog extends MageDialog { private int lastX = 500; private int lastY = 300; - /** Creates new form CombatDialog */ + /** Creates new form COMBAT */ public CombatDialog() { JPanel contentPane = new JPanel() { diff --git a/Mage.Common/src/main/java/mage/utils/DeckBuilder.java b/Mage.Common/src/main/java/mage/utils/DeckBuilder.java index 74615c9bff..6d599f935c 100644 --- a/Mage.Common/src/main/java/mage/utils/DeckBuilder.java +++ b/Mage.Common/src/main/java/mage/utils/DeckBuilder.java @@ -164,10 +164,7 @@ public final class DeckBuilder { } } if (count > 0) { - Integer typeCount = colorCount.get(symbol); - if (typeCount == null) { - typeCount = 0; - } + Integer typeCount = colorCount.getOrDefault(symbol, 0); typeCount += 1; colorCount.put(symbol, typeCount); } @@ -243,9 +240,9 @@ public final class DeckBuilder { int type; if (card.isCreature()) { type = 10; - } else if (card.getSubtype(null).contains(SubType.EQUIPMENT)) { + } else if (card.hasSubtype(SubType.EQUIPMENT, null)) { type = 8; - } else if (card.getSubtype(null).contains(SubType.AURA)) { + } else if (card.hasSubtype(SubType.AURA, null)) { type = 5; } else if (card.isInstant()) { type = 7; @@ -283,10 +280,7 @@ public final class DeckBuilder { multicolor += 1; colors.add(symbol); } - Integer typeCount = singleCount.get(symbol); - if (typeCount == null) { - typeCount = 0; - } + Integer typeCount = singleCount.getOrDefault(symbol, 0); typeCount += 1; singleCount.put(symbol, typeCount); maxSingleCount = Math.max(maxSingleCount, typeCount); diff --git a/Mage.Server/src/main/java/mage/server/record/TableRecordRepository.java b/Mage.Server/src/main/java/mage/server/record/TableRecordRepository.java index 6c7cbd49ea..d6d7997c41 100644 --- a/Mage.Server/src/main/java/mage/server/record/TableRecordRepository.java +++ b/Mage.Server/src/main/java/mage/server/record/TableRecordRepository.java @@ -13,6 +13,7 @@ import org.apache.log4j.Logger; import java.io.File; import java.sql.SQLException; +import java.util.Collections; import java.util.List; public enum TableRecordRepository { @@ -63,7 +64,7 @@ public enum TableRecordRepository { } catch (SQLException ex) { Logger.getLogger(TableRecordRepository.class).error("Error getting table_records from DB - ", ex); } - return null; + return Collections.emptyList(); } public void closeDB() { diff --git a/Mage.Server/src/main/java/mage/server/record/UserStatsRepository.java b/Mage.Server/src/main/java/mage/server/record/UserStatsRepository.java index a7b47617d8..0bbe5cab29 100644 --- a/Mage.Server/src/main/java/mage/server/record/UserStatsRepository.java +++ b/Mage.Server/src/main/java/mage/server/record/UserStatsRepository.java @@ -16,10 +16,7 @@ import org.apache.log4j.Logger; import java.io.File; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; public enum UserStatsRepository { @@ -89,7 +86,7 @@ public enum UserStatsRepository { } catch (SQLException ex) { Logger.getLogger(UserStatsRepository.class).error("Error getting all users from DB - ", ex); } - return null; + return Collections.emptyList(); } public long getLatestEndTimeMs() { diff --git a/Mage.Server/src/main/java/mage/server/util/Config.java b/Mage.Server/src/main/java/mage/server/util/Config.java index d21319ccba..73a1cf7a82 100644 --- a/Mage.Server/src/main/java/mage/server/util/Config.java +++ b/Mage.Server/src/main/java/mage/server/util/Config.java @@ -12,6 +12,8 @@ import org.apache.log4j.Logger; */ public final class Config { + private Config(){} + private static final Logger logger = Logger.getLogger(Config.class); static { diff --git a/Mage.Server/src/main/java/mage/server/util/ServerMessagesUtil.java b/Mage.Server/src/main/java/mage/server/util/ServerMessagesUtil.java index 7c822046cd..942718882d 100644 --- a/Mage.Server/src/main/java/mage/server/util/ServerMessagesUtil.java +++ b/Mage.Server/src/main/java/mage/server/util/ServerMessagesUtil.java @@ -8,6 +8,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Scanner; import java.util.concurrent.Executors; @@ -52,7 +53,6 @@ public enum ServerMessagesUtil { } - public List getMessages() { lock.readLock().lock(); try { @@ -66,9 +66,7 @@ public enum ServerMessagesUtil { log.debug("Reading server messages..."); List motdMessages = readFromFile(); List newMessages = new ArrayList<>(); - if (motdMessages != null) { - newMessages.addAll(motdMessages); - } + newMessages.addAll(motdMessages); newMessages.add(getServerStatistics()); newMessages.add(getServerStatistics2()); @@ -83,7 +81,7 @@ public enum ServerMessagesUtil { private List readFromFile() { if (ignore) { - return null; + return Collections.emptyList(); } File externalFile = null; if (pathToExternalMessages != null) { @@ -120,7 +118,7 @@ public enum ServerMessagesUtil { } if (is == null) { log.warn("Couldn't find server.msg"); - return null; + return Collections.emptyList(); } Scanner scanner = null; @@ -133,8 +131,8 @@ public enum ServerMessagesUtil { newMessages.add(message.trim()); } } - } catch(Exception e) { - log.error(e,e); + } catch (Exception e) { + log.error(e, e); } finally { StreamUtils.closeQuietly(scanner); StreamUtils.closeQuietly(is); @@ -168,7 +166,7 @@ public enum ServerMessagesUtil { return statistics.toString(); } -// private Timer timer = new Timer(1000 * 60, new ActionListener() { + // private Timer timer = new Timer(1000 * 60, new ActionListener() { // public void actionPerformed(ActionEvent e) { // reloadMessages(); // } diff --git a/Mage.Server/src/main/java/mage/server/util/Splitter.java b/Mage.Server/src/main/java/mage/server/util/Splitter.java index 2a1b1f980d..6290a80d47 100644 --- a/Mage.Server/src/main/java/mage/server/util/Splitter.java +++ b/Mage.Server/src/main/java/mage/server/util/Splitter.java @@ -11,6 +11,8 @@ import mage.players.Player; */ public final class Splitter { + private Splitter(){} + public static List split(Game game, UUID playerId) { List players = new ArrayList<>(); //players.add(playerId); // add original player 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 96a69327d1..382021e4cf 100644 --- a/Mage.Server/src/main/java/mage/server/util/SystemUtil.java +++ b/Mage.Server/src/main/java/mage/server/util/SystemUtil.java @@ -31,6 +31,8 @@ import java.util.stream.Collectors; */ public final class SystemUtil { + private SystemUtil(){} + public static final DateFormat dateFormat = new SimpleDateFormat("yy-M-dd HH:mm:ss"); private static final String INIT_FILE_PATH = "config" + File.separator + "init.txt"; @@ -120,7 +122,7 @@ public final class SystemUtil { String cardInfo = card.getName() + " - " + card.getExpansionSetCode(); // optional info - ArrayList resInfo = new ArrayList<>(); + List resInfo = new ArrayList<>(); for (String param : commandParams) { switch (param) { case PARAM_COLOR_COST: @@ -147,7 +149,7 @@ public final class SystemUtil { } } - if (resInfo.size() > 0) { + if (!resInfo.isEmpty()) { cardInfo += ": " + resInfo.stream().collect(Collectors.joining("; ")); } @@ -555,12 +557,9 @@ public final class SystemUtil { * @return */ private static Optional findPlayer(Game game, String name) { - for (Player player : game.getPlayers().values()) { - if (player.getName().equals(name)) { - return Optional.of(player); - } - } - return Optional.empty(); + return game.getPlayers().values().stream() + .filter(player -> player.getName().equals(name)).findFirst(); + } public static String sanitize(String input) { diff --git a/Mage.Sets/src/mage/cards/a/Antagonism.java b/Mage.Sets/src/mage/cards/a/Antagonism.java index 818a31125e..0ad3603e87 100644 --- a/Mage.Sets/src/mage/cards/a/Antagonism.java +++ b/Mage.Sets/src/mage/cards/a/Antagonism.java @@ -19,12 +19,12 @@ import mage.watchers.common.BloodthirstWatcher; */ public final class Antagonism extends CardImpl { - private static final String rule = "{this} deals 2 damage to that player unless one of his or her opponents was dealt damage this turn"; + private static final String rule = "{this} deals 2 damage to that player unless one of their opponents was dealt damage this turn"; public Antagonism(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{R}"); - // At the beginning of each player's end step, Antagonism deals 2 damage to that player unless one of his or her opponents was dealt damage this turn. + // At the beginning of each player's end step, Antagonism deals 2 damage to that player unless one of their opponents was dealt damage this turn. this.addAbility(new BeginningOfEndStepTriggeredAbility(new ConditionalOneShotEffect(new DamageTargetEffect(2), new OpponentWasNotDealtDamageCondition(), rule), TargetController.ANY, false)); diff --git a/Mage.Sets/src/mage/cards/n/NullChamber.java b/Mage.Sets/src/mage/cards/n/NullChamber.java index 43e5cf667c..c235e31d0f 100644 --- a/Mage.Sets/src/mage/cards/n/NullChamber.java +++ b/Mage.Sets/src/mage/cards/n/NullChamber.java @@ -53,78 +53,6 @@ public final class NullChamber extends CardImpl { } } -class NullChamberChooseACardNameEffect extends OneShotEffect { - - public static String INFO_KEY = "NAMED_CARD"; - - public enum TypeOfName { - NOT_BASIC_LAND_NAME, - } - - private final TypeOfName typeOfName; - - public NullChamberChooseACardNameEffect(TypeOfName typeOfName) { - super(Outcome.Detriment); - this.typeOfName = typeOfName; - staticText = setText(); - } - - public NullChamberChooseACardNameEffect(final NullChamberChooseACardNameEffect effect) { - super(effect); - this.typeOfName = effect.typeOfName; - } - - @Override - public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); - Player opponent = game.getPlayer(source.getFirstTarget()); - MageObject sourceObject = game.getPermanentEntering(source.getSourceId()); - if (sourceObject == null) { - sourceObject = game.getObject(source.getSourceId()); - } - if (controller != null - && opponent != null - && sourceObject != null) { - Choice cardChoice = new ChoiceImpl(); - switch (typeOfName) { - case NOT_BASIC_LAND_NAME: - cardChoice.setChoices(CardRepository.instance.getNotBasicLandNames()); - cardChoice.setMessage("Choose a card name other than a basic land card name"); - break; - } - cardChoice.clearChoice(); - if (controller.choose(Outcome.Detriment, cardChoice, game)) { - String cardName = cardChoice.getChoice(); - if (!game.isSimulation()) { - game.informPlayers(sourceObject.getLogName() + ", named card: [" + cardName + ']'); - } - game.getState().setValue(source.getSourceId().toString() + INFO_KEY, cardName); - if (sourceObject instanceof Permanent) { - ((Permanent) sourceObject).addInfo(INFO_KEY, CardUtil.addToolTipMarkTags("Named card: " + cardName), game); - } - return true; - } - } - return false; - } - - @Override - public NullChamberChooseACardNameEffect copy() { - return new NullChamberChooseACardNameEffect(this); - } - - private String setText() { - StringBuilder sb = new StringBuilder("choose a "); - switch (typeOfName) { - case NOT_BASIC_LAND_NAME: - sb.append("card name other than a basic land card"); - break; - } - sb.append(" name"); - return sb.toString(); - } -} - class NullChamberReplacementEffect extends ContinuousRuleModifyingEffectImpl { diff --git a/Mage.Sets/src/mage/cards/v/VenarianGold.java b/Mage.Sets/src/mage/cards/v/VenarianGold.java index cb25f2c231..3de871a055 100644 --- a/Mage.Sets/src/mage/cards/v/VenarianGold.java +++ b/Mage.Sets/src/mage/cards/v/VenarianGold.java @@ -71,7 +71,7 @@ class VenarianGoldValue implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { MageObject mageObject = game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.STACK); - if (mageObject != null && mageObject instanceof StackObject) { + if (mageObject instanceof StackObject) { return ((StackObject) mageObject).getStackAbility().getManaCostsToPay().getX(); } return 0; diff --git a/Mage.Sets/src/mage/cards/w/WallOfShadows.java b/Mage.Sets/src/mage/cards/w/WallOfShadows.java index d87ffe7d98..248b0bf21e 100644 --- a/Mage.Sets/src/mage/cards/w/WallOfShadows.java +++ b/Mage.Sets/src/mage/cards/w/WallOfShadows.java @@ -111,7 +111,7 @@ class CanTargetOnlyWallsPredicate implements Predicate { for (Mode mode : stackObject.getStackAbility().getModes().values()) { for (Target target : mode.getTargets()) { Filter filter = target.getFilter(); - if (filter != null && filter instanceof FilterPermanent) { + if (filter instanceof FilterPermanent) { for (Object predicate : filter.getPredicates()) { if (predicate instanceof SubtypePredicate) { if (predicate.toString().equals("Subtype(Wall)")) { diff --git a/Mage/src/main/java/mage/abilities/effects/common/SkipNextDrawStepTargetEffect.java b/Mage/src/main/java/mage/abilities/effects/common/SkipNextDrawStepTargetEffect.java index 2f1ba7d187..e0d819beaf 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/SkipNextDrawStepTargetEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/SkipNextDrawStepTargetEffect.java @@ -21,7 +21,7 @@ public class SkipNextDrawStepTargetEffect extends ReplacementEffectImpl { public SkipNextDrawStepTargetEffect() { super(Duration.OneUse, Outcome.Detriment); - staticText = "Target player skips his or her next draw step"; + staticText = "Target player skips their next draw step"; } public SkipNextDrawStepTargetEffect(final SkipNextDrawStepTargetEffect effect) { diff --git a/Mage/src/main/java/mage/abilities/keyword/BountyAbility.java b/Mage/src/main/java/mage/abilities/keyword/BountyAbility.java index e41e160ec7..0879c6608b 100644 --- a/Mage/src/main/java/mage/abilities/keyword/BountyAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/BountyAbility.java @@ -19,23 +19,23 @@ import mage.filter.predicate.permanent.CounterPredicate; */ public class BountyAbility extends DiesCreatureTriggeredAbility { - private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature an opponent controls with a bounty counter on it"); + private static final FilterCreaturePermanent bountyCounterFilter = new FilterCreaturePermanent("creature an opponent controls with a bounty counter on it"); static { - filter.add(new ControllerPredicate(TargetController.OPPONENT)); - filter.add(new CounterPredicate(CounterType.BOUNTY)); + bountyCounterFilter.add(new ControllerPredicate(TargetController.OPPONENT)); + bountyCounterFilter.add(new CounterPredicate(CounterType.BOUNTY)); } public BountyAbility(Effect effect) { - super(effect, false, filter); + super(effect, false, bountyCounterFilter); } public BountyAbility(Effect effect, boolean optional) { - super(effect, optional, filter); + super(effect, optional, bountyCounterFilter); } public BountyAbility(Effect effect, boolean optional, boolean setTargetPointer) { - super(effect, optional, filter, setTargetPointer); + super(effect, optional, bountyCounterFilter, setTargetPointer); } public BountyAbility(final BountyAbility ability) {