game.addTableEventListener(
new Listener<TableEvent> () {
@Override
public void event(TableEvent event) {
try {
PriorityTimer timer;
UUID playerId;
switch (event.getEventType()) {
case UPDATE:
updateGame();
break;
case INFO:
ChatManager.getInstance().broadcast(chatId, "", event.getMessage(), MessageColor.BLACK, true, ChatMessage.MessageType.GAME);
logger.trace(game.getId() + " " + event.getMessage());
break;
case STATUS:
ChatManager.getInstance().broadcast(chatId, "", event.getMessage(), MessageColor.ORANGE, event.getWithTime(), ChatMessage.MessageType.GAME);
logger.trace(game.getId() + " " + event.getMessage());
break;
case ERROR:
error(event.getMessage(), event.getException());
break;
case END_GAME_INFO:
endGameInfo();
break;
case INIT_TIMER:
final UUID initPlayerId = event.getPlayerId();
if (initPlayerId == null) {
throw new MageException("INIT_TIMER: playerId can't be null");
}
createPlayerTimer(event.getPlayerId(), game.getPriorityTime());
break;
case RESUME_TIMER:
playerId = event.getPlayerId();
if (playerId == null) {
throw new MageException("RESUME_TIMER: playerId can't be null");
}
timer = timers.get(playerId);
if (timer == null) {
Player player = game.getState().getPlayer(playerId);
if (player != null) {
timer = createPlayerTimer(event.getPlayerId(), player.getPriorityTimeLeft());
} else {
throw new MageException("RESUME_TIMER: player can't be null");
}
}
timer.resume();
break;
case PAUSE_TIMER:
playerId = event.getPlayerId();
if (playerId == null) {
throw new MageException("PAUSE_TIMER: playerId can't be null");
}
timer = timers.get(playerId);
if (timer == null) {
throw new MageException("PAUSE_TIMER: couldn't find timer for player: " + playerId);
}
timer.pause();
break;
}
} catch (MageException ex) {
logger.fatal("Table event listener error ", ex);
}