Some NPE fixing for server and client.

This commit is contained in:
LevelX2 2014-08-12 08:51:06 +02:00
parent a2e93986bc
commit 9020a287d6
3 changed files with 35 additions and 18 deletions

View file

@ -192,7 +192,6 @@ public class TournamentPanel extends javax.swing.JPanel {
}
public void update(TournamentView tournament) {
if (!firstInitDone) {
Component c = this.getParent();
while (c != null && !(c instanceof TournamentPane)) {
@ -689,7 +688,7 @@ class UpdateTournamentTask extends SwingWorker<Void, TournamentView> {
@Override
protected void process(List<TournamentView> view) {
if (view != null) { // if user disconnects, view can be null for a short time
if (view != null && view.size() > 0) { // if user disconnects, view can be null for a short time
panel.update(view.get(0));
}
}

View file

@ -39,6 +39,7 @@ import java.util.concurrent.TimeUnit;
import mage.cards.decks.Deck;
import mage.constants.ManaType;
import mage.game.Table;
import mage.game.tournament.TournamentPlayer;
import mage.interfaces.callback.ClientCallback;
import mage.players.net.UserData;
import mage.server.draft.DraftSession;
@ -73,7 +74,7 @@ public class User {
private final Map<UUID, TournamentSession> constructing;
private final Map<UUID, Deck> sideboarding;
private final List<UUID> watchedGames;
private final ArrayList<UUID> tablesToRemove = new ArrayList<>();
private String sessionId;
private String info;
private Date lastActivity;
@ -365,28 +366,37 @@ public class User {
disconnectInfo = new StringBuilder(" (discon. ").append(getDisconnectDuration()).append(")").toString();
}
int draft = 0, match = 0, sideboard = 0, tournament = 0, construct = 0;
for (Map.Entry<UUID, Table> tableEntry : tables.entrySet()) {
if (tableEntry != null) {
Table table = tableEntry.getValue();
if (table != null) {
if (table.isTournament()) {
if (!table.getTournament().getPlayer(tableEntry.getKey()).isEliminated()) {
switch (table.getState()) {
case CONSTRUCTING:
construct++;
break;
case DRAFTING:
draft++;
break;
case DUELING:
tournament++;
break;
}
if (!isConnected()) {
table.getTournament().getPlayer(tableEntry.getKey()).setDisconnectInfo(disconnectInfo);
if (tableEntry.getKey() != null) {
TournamentPlayer tournamentPlayer = table.getTournament().getPlayer(tableEntry.getKey());
if (tournamentPlayer != null && !tournamentPlayer.isEliminated()) {
switch (table.getState()) {
case CONSTRUCTING:
construct++;
break;
case DRAFTING:
draft++;
break;
case DUELING:
tournament++;
break;
}
if (!isConnected()) {
table.getTournament().getPlayer(tableEntry.getKey()).setDisconnectInfo(disconnectInfo);
} else {
table.getTournament().getPlayer(tableEntry.getKey()).setDisconnectInfo("");
}
} else {
table.getTournament().getPlayer(tableEntry.getKey()).setDisconnectInfo("");
tablesToRemove.add(tableEntry.getKey());
logger.error(getName() + " tournament player missing - tournamentId:" + table.getId(), null);
}
} else {
logger.error(getName() + " tournament key missing - tournamentId: " + table.getId(), null);
}
} else {
switch (table.getState()) {
@ -401,6 +411,12 @@ public class User {
}
}
}
if (!tablesToRemove.isEmpty()) {
for (UUID tableKey : tablesToRemove) {
tables.remove(tableKey);
}
tablesToRemove.clear();
}
if (match > 0) {
sb.append("Match: ").append(match).append(" ");
}

View file

@ -45,6 +45,8 @@ since 1.3.0-2014-07-19
git log 75eb0bdfdf36ba83dd5a3e2c6a204ceb186c9d5e..HEAD --diff-filter=A --name-status | sed -ne "s/^A[^u]Mage.Sets\/src\/mage\/sets\///p" | sort > added_cards.txt
since 1.3.0-2014-07-30
git log 69ce53e6e8036bf01bdd090e8785f4d63c486d1e..HEAD --diff-filter=A --name-status | sed -ne "s/^A[^u]Mage.Sets\/src\/mage\/sets\///p" | sort > added_cards.txt
since 1.3.0-2014-08-11
git log 709dc83ae6fd6778e5b52e5176a978f1c6fda3b7..HEAD --diff-filter=A --name-status | sed -ne "s/^A[^u]Mage.Sets\/src\/mage\/sets\///p" | sort > added_cards.txt