Fixed some possible NPE of server.

This commit is contained in:
LevelX2 2014-09-07 22:01:38 +02:00
parent bb0be3aea3
commit 65fdaba28d
2 changed files with 36 additions and 29 deletions

View file

@ -700,39 +700,41 @@ public class TableController {
} }
private void matchEnd() { private void matchEnd() {
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) { if (match != null) {
MatchPlayer matchPlayer = match.getPlayer(entry.getValue()); for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
// opponent(s) left during sideboarding MatchPlayer matchPlayer = match.getPlayer(entry.getValue());
if (matchPlayer != null) { // opponent(s) left during sideboarding
if(!matchPlayer.hasQuit()) { if (matchPlayer != null) {
User user = UserManager.getInstance().getUser(entry.getKey()); if(!matchPlayer.hasQuit()) {
if (user != null) { User user = UserManager.getInstance().getUser(entry.getKey());
if (table.getState().equals(TableState.SIDEBOARDING)) { if (user != null) {
StringBuilder sb = new StringBuilder(); if (table.getState().equals(TableState.SIDEBOARDING)) {
if (table.isTournamentSubTable()) { StringBuilder sb = new StringBuilder();
sb.append("Your tournament match of round "); if (table.isTournamentSubTable()) {
sb.append(table.getTournament().getRounds().size()); sb.append("Your tournament match of round ");
sb.append(" is over. "); sb.append(table.getTournament().getRounds().size());
} else { sb.append(" is over. ");
sb.append("Match [").append(match.getName()).append("] is over. "); } else {
sb.append("Match [").append(match.getName()).append("] is over. ");
}
if (match.getPlayers().size() > 2) {
sb.append("All your opponents have lost or quit the match.");
} else {
sb.append("Your opponent has quit the match.");
}
user.showUserMessage("Match info", sb.toString());
} }
if (match.getPlayers().size() > 2) { // remove table from user - table manager holds table for display of finished matches
sb.append("All your opponents have lost or quit the match."); if (!table.isTournamentSubTable()) {
} else { user.removeTable(entry.getValue());
sb.append("Your opponent has quit the match.");
} }
user.showUserMessage("Match info", sb.toString());
}
// remove table from user - table manager holds table for display of finished matches
if (!table.isTournamentSubTable()) {
user.removeTable(entry.getValue());
} }
} }
} }
} }
// free resources no longer needed
match.cleanUpOnMatchEnd(ConfigSettings.getInstance().isSaveGameActivated());
} }
// free resources no longer needed
match.cleanUpOnMatchEnd(ConfigSettings.getInstance().isSaveGameActivated());
} }
private synchronized void setupTimeout(int seconds) { private synchronized void setupTimeout(int seconds) {

View file

@ -230,7 +230,12 @@ class TableListSorter implements Comparator<Table> {
if (two.getState().equals(TableState.READY_TO_START) || two.getState().equals(TableState.WAITING) || two.getState().equals(TableState.STARTING)) { if (two.getState().equals(TableState.READY_TO_START) || two.getState().equals(TableState.WAITING) || two.getState().equals(TableState.STARTING)) {
return 1; // two has higher priority return 1; // two has higher priority
} else if (one.getEndTime() == null) { } else if (one.getEndTime() == null) {
if (two.getEndTime() == null) { if (two.getEndTime() == null) {
if (two.getStartTime() == null) {
return -1;
} else if (one.getStartTime() == null) {
return 1;
}
return two.getStartTime().compareTo(one.getStartTime()); return two.getStartTime().compareTo(one.getStartTime());
} else { } else {
return -1; return -1;