mirror of
https://github.com/correl/mage.git
synced 2024-12-25 19:25:41 +00:00
Fixed a bug that players were not removed properly from matches or tournaments they left before the match or tournament was started.
This commit is contained in:
parent
1df4946135
commit
a070c5a8e1
4 changed files with 27 additions and 2 deletions
|
@ -281,7 +281,18 @@ public class TableController {
|
|||
|
||||
public synchronized void leaveTable(UUID userId) {
|
||||
if (table.getState() == TableState.WAITING || table.getState() == TableState.STARTING) {
|
||||
table.leaveTable(userPlayerMap.get(userId));
|
||||
UUID playerId = userPlayerMap.get(userId);
|
||||
if (playerId != null) {
|
||||
table.leaveTable(playerId);
|
||||
if (table.isTournament()) {
|
||||
tournament.leave(playerId);
|
||||
} else {
|
||||
match.leave(playerId);
|
||||
}
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
user.removeTable(playerId);
|
||||
userPlayerMap.remove(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,10 @@ public interface Match {
|
|||
boolean isMatchOver();
|
||||
List<MatchPlayer> getPlayers();
|
||||
MatchPlayer getPlayer(UUID playerId);
|
||||
|
||||
void addPlayer(Player player, Deck deck);
|
||||
boolean leave(UUID playerId);
|
||||
|
||||
void submitDeck(UUID playerId, Deck deck);
|
||||
void updateDeck(UUID playerId, Deck deck);
|
||||
void startMatch() throws GameException;
|
||||
|
|
|
@ -77,6 +77,15 @@ public abstract class MatchImpl implements Match {
|
|||
players.add(mPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean leave(UUID playerId) {
|
||||
MatchPlayer mPlayer = getPlayer(playerId);
|
||||
if (mPlayer != null) {
|
||||
return players.remove(mPlayer);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMatch() throws GameException {
|
||||
|
||||
|
|
|
@ -102,7 +102,9 @@ public abstract class TournamentImpl implements Tournament {
|
|||
|
||||
@Override
|
||||
public void leave(UUID playerId) {
|
||||
//TODO: implement this
|
||||
if (players.containsKey(playerId)) {
|
||||
players.remove(playerId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue