diff --git a/Mage.Client/src/main/java/mage/client/tournament/TournamentPanel.java b/Mage.Client/src/main/java/mage/client/tournament/TournamentPanel.java index 92296741c1..868da4a12f 100644 --- a/Mage.Client/src/main/java/mage/client/tournament/TournamentPanel.java +++ b/Mage.Client/src/main/java/mage/client/tournament/TournamentPanel.java @@ -34,7 +34,8 @@ package mage.client.tournament; -import java.awt.*; +import java.awt.Component; +import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.text.DateFormat; import java.util.ArrayList; @@ -42,7 +43,10 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; -import javax.swing.*; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JOptionPane; +import javax.swing.SwingWorker; import javax.swing.table.AbstractTableModel; import mage.client.MageFrame; import mage.client.chat.ChatPanel; @@ -66,10 +70,10 @@ public class TournamentPanel extends javax.swing.JPanel { private UUID tournamentId; private boolean firstInitDone = false; private Session session; - private TournamentPlayersTableModel playersModel; + private final TournamentPlayersTableModel playersModel; private TournamentMatchesTableModel matchesModel; private UpdateTournamentTask updateTask; - private DateFormat df; + private final DateFormat df; /** Creates new form TournamentPanel */ public TournamentPanel() { @@ -448,7 +452,7 @@ public class TournamentPanel extends javax.swing.JPanel { } class TournamentPlayersTableModel extends AbstractTableModel { - private String[] columnNames = new String[]{"Player Name", "State", "Points", "Results"}; + private final String[] columnNames = new String[]{"Player Name", "State", "Points", "Results"}; private TournamentPlayerView[] players = new TournamentPlayerView[0]; public void loadData(TournamentView tournament) { @@ -508,7 +512,7 @@ class TournamentMatchesTableModel extends AbstractTableModel { public static final int ACTION_COLUMN = 4; // column the action is located - private String[] columnNames = new String[]{"Round Number", "Players", "State", "Result", "Action"}; + private final String[] columnNames = new String[]{"Round Number", "Players", "State", "Result", "Action"}; private TournamentGameView[] games = new TournamentGameView[0]; private boolean watchingAllowed; @@ -582,19 +586,16 @@ class TournamentMatchesTableModel extends AbstractTableModel { @Override public boolean isCellEditable(int rowIndex, int columnIndex) { - if (columnIndex != ACTION_COLUMN) { - return false; - } - return true; + return columnIndex == ACTION_COLUMN; } } class UpdateTournamentTask extends SwingWorker { - private Session session; - private UUID tournamentId; - private TournamentPanel panel; + private final Session session; + private final UUID tournamentId; + private final TournamentPanel panel; private static final Logger logger = Logger.getLogger(UpdateTournamentTask.class); diff --git a/Mage.Common/src/mage/view/TournamentGameView.java b/Mage.Common/src/mage/view/TournamentGameView.java index fa237811c3..201771e75e 100644 --- a/Mage.Common/src/mage/view/TournamentGameView.java +++ b/Mage.Common/src/mage/view/TournamentGameView.java @@ -41,13 +41,13 @@ import mage.game.tournament.TournamentPairing; public class TournamentGameView implements Serializable { private static final long serialVersionUID = 1L; - private int roundNum; - private UUID matchId; - private UUID gameId; - private String state; - private String result; - private String players; - private UUID tableId; + private final int roundNum; + private final UUID matchId; + private final UUID gameId; + private final String state; + private final String result; + private final String players; + private final UUID tableId; TournamentGameView(int roundNum, TournamentPairing pair, Game game) { this.roundNum = roundNum; diff --git a/Mage.Common/src/mage/view/TournamentPlayerView.java b/Mage.Common/src/mage/view/TournamentPlayerView.java index 77a3b5c999..812941885e 100644 --- a/Mage.Common/src/mage/view/TournamentPlayerView.java +++ b/Mage.Common/src/mage/view/TournamentPlayerView.java @@ -39,11 +39,11 @@ import mage.game.tournament.TournamentPlayer; public class TournamentPlayerView implements Serializable { private static final long serialVersionUID = 1L; - private String name; - private String state; - private String results; - private int points; - private boolean quit; + private final String name; + private final String state; + private final String results; + private final int points; + private final boolean quit; TournamentPlayerView(TournamentPlayer player) { this.name = player.getPlayer().getName(); diff --git a/Mage.Common/src/mage/view/TournamentTypeView.java b/Mage.Common/src/mage/view/TournamentTypeView.java index 1ba2081d25..b524e6a96e 100644 --- a/Mage.Common/src/mage/view/TournamentTypeView.java +++ b/Mage.Common/src/mage/view/TournamentTypeView.java @@ -38,14 +38,14 @@ import mage.game.tournament.TournamentType; public class TournamentTypeView implements Serializable { private static final long serialVersionUID = 1L; - private String name; - private int minPlayers; - private int maxPlayers; - private int numBoosters; - private boolean draft; - private boolean limited; - private boolean cubeBooster; - private boolean elimination; + private final String name; + private final int minPlayers; + private final int maxPlayers; + private final int numBoosters; + private final boolean draft; + private final boolean limited; + private final boolean cubeBooster; + private final boolean elimination; public TournamentTypeView(TournamentType tournamentType) { diff --git a/Mage.Common/src/mage/view/TournamentView.java b/Mage.Common/src/mage/view/TournamentView.java index 99efa789e4..1442764001 100644 --- a/Mage.Common/src/mage/view/TournamentView.java +++ b/Mage.Common/src/mage/view/TournamentView.java @@ -43,16 +43,16 @@ import mage.game.tournament.TournamentPlayer; public class TournamentView implements Serializable { private static final long serialVersionUID = 1L; - private String tournamentName; - private String tournamentType; + private final String tournamentName; + private final String tournamentType; - private Date startTime; - private Date endTime; + private final Date startTime; + private final Date endTime; - private boolean watchingAllowed; + private final boolean watchingAllowed; - private List rounds = new ArrayList(); - private List players = new ArrayList(); + private final List rounds = new ArrayList(); + private final List players = new ArrayList(); public TournamentView(Tournament tournament) { diff --git a/Mage/src/mage/game/tournament/Round.java b/Mage/src/mage/game/tournament/Round.java index 11b711153c..cffe60001a 100644 --- a/Mage/src/mage/game/tournament/Round.java +++ b/Mage/src/mage/game/tournament/Round.java @@ -38,12 +38,14 @@ import java.util.UUID; */ public class Round { - private int roundNum; - private List pairs = new ArrayList(); - private List playerByes = new ArrayList(); + private final int roundNum; + private final Tournament tournament; + private final List pairs = new ArrayList(); + private final List playerByes = new ArrayList(); - public Round(int roundNum) { + public Round(int roundNum, Tournament tournament) { this.roundNum = roundNum; + this.tournament = tournament; } public void addPairing(TournamentPairing match) { @@ -68,12 +70,18 @@ public class Round { } public boolean isRoundOver() { + boolean roundIsOver = true; for (TournamentPairing pair: pairs) { if (!pair.getMatch().isMatchOver()) { - return false; + roundIsOver = false; + } else { + if (!pair.isAlreadyPublished()) { + tournament.updateResults(); + pair.setAlreadyPublished(true); + } } } - return true; + return roundIsOver; } public List getPlayerByes() { diff --git a/Mage/src/mage/game/tournament/Tournament.java b/Mage/src/mage/game/tournament/Tournament.java index bdabf7ee1c..aaf7fe4b1d 100644 --- a/Mage/src/mage/game/tournament/Tournament.java +++ b/Mage/src/mage/game/tournament/Tournament.java @@ -53,6 +53,7 @@ public interface Tournament { Collection getRounds(); List getSets(); + void updateResults(); void setBoosterInfo(String setInfo); /** * Gives back a String that shows the included sets (e.g. "3xRTR" or "1xDGM 1xGTC 1xRTR") or cube name diff --git a/Mage/src/mage/game/tournament/TournamentImpl.java b/Mage/src/mage/game/tournament/TournamentImpl.java index 0d81ff46f8..53a0658287 100644 --- a/Mage/src/mage/game/tournament/TournamentImpl.java +++ b/Mage/src/mage/game/tournament/TournamentImpl.java @@ -28,20 +28,30 @@ package mage.game.tournament; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.UUID; import java.util.concurrent.CopyOnWriteArrayList; import mage.cards.Card; import mage.cards.ExpansionSet; import mage.cards.decks.Deck; import mage.constants.TournamentPlayerState; import mage.game.draft.DraftCube; -import mage.game.events.*; +import mage.game.events.Listener; +import mage.game.events.PlayerQueryEvent; +import mage.game.events.PlayerQueryEventSource; +import mage.game.events.TableEvent; import mage.game.events.TableEvent.EventType; +import mage.game.events.TableEventSource; import mage.game.match.Match; import mage.players.Player; import org.apache.log4j.Logger; - /** * * @author BetaSteward_at_googlemail.com @@ -164,7 +174,7 @@ public abstract class TournamentImpl implements Tournament { } protected Round createRoundRandom() { - Round round = new Round(rounds.size() + 1); + Round round = new Round(rounds.size() + 1, this); rounds.add(round); List roundPlayers = getActivePlayers(); while (roundPlayers.size() > 1) { @@ -213,7 +223,11 @@ public abstract class TournamentImpl implements Tournament { return activePlayers; } - protected void updateResults() { + /** + * + */ + @Override + public void updateResults() { for (TournamentPlayer player: players.values()) { player.setResults(""); player.setPoints(0); @@ -224,27 +238,37 @@ public abstract class TournamentImpl implements Tournament { UUID player1Id = pair.getPlayer1().getPlayer().getId(); UUID player2Id = pair.getPlayer2().getPlayer().getId(); Match match = pair.getMatch(); - StringBuilder sb1 = new StringBuilder(players.get(player1Id).getResults()); - StringBuilder sb2 = new StringBuilder(players.get(player2Id).getResults()); - sb1.append(pair.getPlayer2().getPlayer().getName()); - sb1.append(" (").append(match.getPlayer(player1Id).getWins()); - sb1.append("-").append(match.getPlayer(player2Id).getWins()).append(") "); - sb2.append(pair.getPlayer1().getPlayer().getName()); - sb2.append(" (").append(match.getPlayer(player2Id).getWins()); - sb2.append("-").append(match.getPlayer(player1Id).getWins()).append(") "); - players.get(player1Id).setResults(sb1.toString()); - players.get(player2Id).setResults(sb2.toString()); - if (match.getPlayer(player1Id).getWins() > match.getPlayer(player2Id).getWins()) { - int points = players.get(player1Id).getPoints(); - players.get(player1Id).setPoints(points + 3); - } else if (match.getPlayer(player1Id).getWins() < match.getPlayer(player2Id).getWins()) { - int points = players.get(player2Id).getPoints(); - players.get(player2Id).setPoints(points + 3); - } else { - int points = players.get(player1Id).getPoints(); - players.get(player1Id).setPoints(points + 1); - points = players.get(player2Id).getPoints(); - players.get(player2Id).setPoints(points + 1); + if (match.isMatchOver()) { + if (round.getRoundNumber() == rounds.size()) { + if (players.get(player1Id).getState().equals(TournamentPlayerState.DUELING)) { + players.get(player1Id).setState(TournamentPlayerState.WAITING); + } + if (players.get(player2Id).getState().equals(TournamentPlayerState.DUELING)) { + players.get(player2Id).setState(TournamentPlayerState.WAITING); + } + } + StringBuilder sb1 = new StringBuilder(players.get(player1Id).getResults()); + StringBuilder sb2 = new StringBuilder(players.get(player2Id).getResults()); + sb1.append(pair.getPlayer2().getPlayer().getName()); + sb1.append(" (").append(match.getPlayer(player1Id).getWins()); + sb1.append("-").append(match.getPlayer(player2Id).getWins()).append(") "); + sb2.append(pair.getPlayer1().getPlayer().getName()); + sb2.append(" (").append(match.getPlayer(player2Id).getWins()); + sb2.append("-").append(match.getPlayer(player1Id).getWins()).append(") "); + players.get(player1Id).setResults(sb1.toString()); + players.get(player2Id).setResults(sb2.toString()); + if (match.getPlayer(player1Id).getWins() > match.getPlayer(player2Id).getWins()) { + int points = players.get(player1Id).getPoints(); + players.get(player1Id).setPoints(points + 3); + } else if (match.getPlayer(player1Id).getWins() < match.getPlayer(player2Id).getWins()) { + int points = players.get(player2Id).getPoints(); + players.get(player2Id).setPoints(points + 3); + } else { + int points = players.get(player1Id).getPoints(); + players.get(player1Id).setPoints(points + 1); + points = players.get(player2Id).getPoints(); + players.get(player2Id).setPoints(points + 1); + } } } for (TournamentPlayer tournamentPlayer : round.getPlayerByes()) { diff --git a/Mage/src/mage/game/tournament/TournamentPairing.java b/Mage/src/mage/game/tournament/TournamentPairing.java index 9c9a4f651a..078e44bb82 100644 --- a/Mage/src/mage/game/tournament/TournamentPairing.java +++ b/Mage/src/mage/game/tournament/TournamentPairing.java @@ -38,15 +38,17 @@ import mage.game.match.MatchPlayer; */ public class TournamentPairing { - private UUID id = UUID.randomUUID(); + private final UUID id = UUID.randomUUID(); private UUID tableId; private Match match; - private TournamentPlayer player1; - private TournamentPlayer player2; + private final TournamentPlayer player1; + private final TournamentPlayer player2; + private boolean alreadyPublished; public TournamentPairing(TournamentPlayer player1, TournamentPlayer player2) { this.player1 = player1; this.player2 = player2; + this.alreadyPublished = false; } public UUID getId() { @@ -98,4 +100,12 @@ public class TournamentPairing { this.tableId = tableId; } + public boolean isAlreadyPublished() { + return alreadyPublished; + } + + public void setAlreadyPublished(boolean alreadyPublished) { + this.alreadyPublished = alreadyPublished; + } + } diff --git a/Mage/src/mage/game/tournament/TournamentSwiss.java b/Mage/src/mage/game/tournament/TournamentSwiss.java index 0db706d599..73ed33c36f 100644 --- a/Mage/src/mage/game/tournament/TournamentSwiss.java +++ b/Mage/src/mage/game/tournament/TournamentSwiss.java @@ -62,7 +62,7 @@ public abstract class TournamentSwiss extends TournamentImpl { } protected Round createRoundSwiss() { - Round round = new Round(rounds.size() + 1); + Round round = new Round(rounds.size() + 1, this); rounds.add(round); List roundPlayers = getActivePlayers(); // sort players by tournament points