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() {
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
MatchPlayer matchPlayer = match.getPlayer(entry.getValue());
// opponent(s) left during sideboarding
if (matchPlayer != null) {
if(!matchPlayer.hasQuit()) {
User user = UserManager.getInstance().getUser(entry.getKey());
if (user != null) {
if (table.getState().equals(TableState.SIDEBOARDING)) {
StringBuilder sb = new StringBuilder();
if (table.isTournamentSubTable()) {
sb.append("Your tournament match of round ");
sb.append(table.getTournament().getRounds().size());
sb.append(" is over. ");
} else {
sb.append("Match [").append(match.getName()).append("] is over. ");
if (match != null) {
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
MatchPlayer matchPlayer = match.getPlayer(entry.getValue());
// opponent(s) left during sideboarding
if (matchPlayer != null) {
if(!matchPlayer.hasQuit()) {
User user = UserManager.getInstance().getUser(entry.getKey());
if (user != null) {
if (table.getState().equals(TableState.SIDEBOARDING)) {
StringBuilder sb = new StringBuilder();
if (table.isTournamentSubTable()) {
sb.append("Your tournament match of round ");
sb.append(table.getTournament().getRounds().size());
sb.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) {
sb.append("All your opponents have lost or quit the match.");
} else {
sb.append("Your opponent has quit the match.");
// remove table from user - table manager holds table for display of finished matches
if (!table.isTournamentSubTable()) {
user.removeTable(entry.getValue());
}
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) {

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)) {
return 1; // two has higher priority
} 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());
} else {
return -1;