Show player joins message in chat window only, if player isn't already connected. Suppres posting of empty strings in the chat window.

This commit is contained in:
LevelX2 2013-03-17 23:44:45 +01:00
parent 0cedc155ae
commit e52c35fec9

View file

@ -56,7 +56,7 @@ public class ChatSession {
public void join(UUID userId) { public void join(UUID userId) {
User user = UserManager.getInstance().getUser(userId); User user = UserManager.getInstance().getUser(userId);
if (user != null) { if (user != null && !clients.containsKey(userId)) {
String userName = user.getName(); String userName = user.getName();
clients.put(userId, userName); clients.put(userId, userName);
broadcast(userName, " has joined", MessageColor.BLACK); broadcast(userName, " has joined", MessageColor.BLACK);
@ -74,17 +74,19 @@ public class ChatSession {
} }
public void broadcast(String userName, String message, MessageColor color) { public void broadcast(String userName, String message, MessageColor color) {
Calendar cal = new GregorianCalendar(); if (!message.isEmpty()) {
final String msg = message; Calendar cal = new GregorianCalendar();
final String time = timeFormatter.format(cal.getTime()); final String msg = message;
final String username = userName; final String time = timeFormatter.format(cal.getTime());
logger.debug("Broadcasting '" + msg + "' for " + chatId); final String username = userName;
for (UUID userId: clients.keySet()) { logger.debug("Broadcasting '" + msg + "' for " + chatId);
User user = UserManager.getInstance().getUser(userId); for (UUID userId: clients.keySet()) {
if (user != null) User user = UserManager.getInstance().getUser(userId);
user.fireCallback(new ClientCallback("chatMessage", chatId, new ChatMessage(username, msg, time, color))); if (user != null)
else user.fireCallback(new ClientCallback("chatMessage", chatId, new ChatMessage(username, msg, time, color)));
kill(userId); else
kill(userId);
}
} }
} }