diff --git a/Mage.Server/src/main/java/mage/server/ChatManager.java b/Mage.Server/src/main/java/mage/server/ChatManager.java index d401d79ba4..0676e31686 100644 --- a/Mage.Server/src/main/java/mage/server/ChatManager.java +++ b/Mage.Server/src/main/java/mage/server/ChatManager.java @@ -20,6 +20,7 @@ import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * @author BetaSteward_at_googlemail.com @@ -320,13 +321,24 @@ public enum ChatManager { UserManager.instance.getUser(userId).ifPresent(user -> sendMessageToUserChats(userId, user.getName() + " " + reason.getMessage())); } + /** + * Send message to all active waiting/tourney/game chats (but not in main lobby) + * + * @param userId + * @param message + */ public void sendMessageToUserChats(UUID userId, String message) { - UserManager.instance.getUser(userId).ifPresent(user - -> getChatSessions() - .stream() - .filter(chat -> !chat.getChatId().equals(GamesRoomManager.instance.getMainChatId())) // ignore main lobby - .filter(chat -> chat.hasUser(userId)) - .forEach(chatSession -> chatSession.broadcast(null, message, MessageColor.BLUE, true, MessageType.STATUS, null))); + UserManager.instance.getUser(userId).ifPresent(user -> { + List chatSessions = getChatSessions().stream() + .filter(chat -> !chat.getChatId().equals(GamesRoomManager.instance.getMainChatId())) // ignore main lobby + .filter(chat -> chat.hasUser(userId)) + .collect(Collectors.toList()); + + if (chatSessions.size() > 0) { + logger.info("INFORM OPPONENTS by " + user.getName() + ": " + message); + chatSessions.forEach(chatSession -> chatSession.broadcast(null, message, MessageColor.BLUE, true, MessageType.STATUS, null)); + } + }); } public void removeUser(UUID userId, DisconnectReason reason) { diff --git a/Mage.Server/src/main/java/mage/server/UserManager.java b/Mage.Server/src/main/java/mage/server/UserManager.java index 2c7cdea698..2331bfa314 100644 --- a/Mage.Server/src/main/java/mage/server/UserManager.java +++ b/Mage.Server/src/main/java/mage/server/UserManager.java @@ -152,7 +152,6 @@ public enum UserManager { -> USER_EXECUTOR.execute( () -> { try { - logger.info("INFORM OPPONENTS by " + user.getName() + ": " + message); ChatManager.instance.sendMessageToUserChats(user.getId(), message); } catch (Exception ex) { handleException(ex);