* Changed table maneger to remove chat sessions that were never removed. Minor formattings.

This commit is contained in:
LevelX2 2014-07-25 15:54:51 +02:00
parent 8bdc94082d
commit e25a60b312
5 changed files with 18 additions and 11 deletions

View file

@ -299,7 +299,7 @@ public class TableWaitingDialog extends MageDialog {
} }
class TableWaitModel extends AbstractTableModel { class TableWaitModel extends AbstractTableModel {
private String[] columnNames = new String[]{"Seat Num", "Player Name", "Player Type"}; private final String[] columnNames = new String[]{"Seat Num", "Player Name", "Player Type"};
private SeatView[] seats = new SeatView[0]; private SeatView[] seats = new SeatView[0];
public void loadData(TableView table) { public void loadData(TableView table) {
@ -362,10 +362,10 @@ class TableWaitModel extends AbstractTableModel {
class UpdateSeatsTask extends SwingWorker<Void, TableView> { class UpdateSeatsTask extends SwingWorker<Void, TableView> {
private Session session; private final Session session;
private UUID roomId; private final UUID roomId;
private UUID tableId; private final UUID tableId;
private TableWaitingDialog dialog; private final TableWaitingDialog dialog;
private int count = 0; private int count = 0;
private static final Logger logger = Logger.getLogger(TableWaitingDialog.class); private static final Logger logger = Logger.getLogger(TableWaitingDialog.class);

View file

@ -69,7 +69,9 @@ public class ChatManager {
} }
public void destroyChatSession(UUID chatId) { public void destroyChatSession(UUID chatId) {
chatSessions.remove(chatId); if (chatId != null) {
chatSessions.remove(chatId);
}
} }
public void broadcast(UUID chatId, String userName, String message, MessageColor color) { public void broadcast(UUID chatId, String userName, String message, MessageColor color) {

View file

@ -205,6 +205,7 @@ public class TableManager {
public boolean removeTable(UUID userId, UUID tableId) { public boolean removeTable(UUID userId, UUID tableId) {
if (isTableOwner(tableId, userId) || UserManager.getInstance().isAdmin(userId)) { if (isTableOwner(tableId, userId) || UserManager.getInstance().isAdmin(userId)) {
leaveTable(userId, tableId); leaveTable(userId, tableId);
ChatManager.getInstance().destroyChatSession(controllers.get(tableId).getChatId());
removeTable(tableId); removeTable(tableId);
return true; return true;
} }
@ -246,6 +247,8 @@ public class TableManager {
public void startMatch(UUID userId, UUID roomId, UUID tableId) { public void startMatch(UUID userId, UUID roomId, UUID tableId) {
if (controllers.containsKey(tableId)) { if (controllers.containsKey(tableId)) {
controllers.get(tableId).startMatch(userId); controllers.get(tableId).startMatch(userId);
// chat of start dialog can be killed
ChatManager.getInstance().destroyChatSession(controllers.get(tableId).getChatId());
} }
} }
@ -264,6 +267,7 @@ public class TableManager {
public void startTournament(UUID userId, UUID roomId, UUID tableId) { public void startTournament(UUID userId, UUID roomId, UUID tableId) {
if (controllers.containsKey(tableId)) { if (controllers.containsKey(tableId)) {
controllers.get(tableId).startTournament(userId); controllers.get(tableId).startTournament(userId);
ChatManager.getInstance().destroyChatSession(controllers.get(tableId).getChatId());
} }
} }
@ -334,9 +338,10 @@ public class TableManager {
public void removeTable(UUID tableId) { public void removeTable(UUID tableId) {
if (tables.containsKey(tableId)) { if (tables.containsKey(tableId)) {
Table table = tables.get(tableId); Table table = tables.get(tableId);
ChatManager.getInstance().destroyChatSession(controllers.get(tableId).getChatId());
controllers.remove(tableId); controllers.remove(tableId);
tables.remove(tableId); tables.remove(tableId);
// If table is not finished, the table has to removed completly (if finished it will be removed in GamesRoomImpl.Update()) // If table is not finished, the table has to be removed completly (if finished it will be removed in GamesRoomImpl.Update())
if (!table.getState().equals(TableState.FINISHED)) { if (!table.getState().equals(TableState.FINISHED)) {
GamesRoomManager.getInstance().removeTable(tableId); GamesRoomManager.getInstance().removeTable(tableId);
} }

View file

@ -40,8 +40,8 @@ public class GamesRoomManager {
private static final GamesRoomManager INSTANCE = new GamesRoomManager(); private static final GamesRoomManager INSTANCE = new GamesRoomManager();
// private static final Logger logger = Logger.getLogger(GamesRoomManager.class); // private static final Logger logger = Logger.getLogger(GamesRoomManager.class);
private ConcurrentHashMap<UUID, GamesRoom> rooms = new ConcurrentHashMap<UUID, GamesRoom>(); private final ConcurrentHashMap<UUID, GamesRoom> rooms = new ConcurrentHashMap<>();
private UUID mainRoomId; private final UUID mainRoomId;
public static GamesRoomManager getInstance() { public static GamesRoomManager getInstance() {
return INSTANCE; return INSTANCE;

View file

@ -70,7 +70,7 @@ public abstract class ContinuousRuleModifiyingEffectImpl extends ContinuousEffec
@Override @Override
public String getInfoMessage(Ability source, Game game) { public String getInfoMessage(Ability source, Game game) {
if (infoMessage == null) { if (infoMessage == null) {
String message = null; String message;
MageObject object = game.getObject(source.getSourceId()); MageObject object = game.getObject(source.getSourceId());
if (object != null) { if (object != null) {
message = source.getRule(object.getLogName()); message = source.getRule(object.getLogName());