use of mage.view.ChatMessage in project mage by magefree.
the class ChatSession method broadcast.
public void broadcast(String userName, String message, MessageColor color, boolean withTime, Game game, MessageType messageType, SoundToPlay soundToPlay) {
if (!message.isEmpty()) {
Set<UUID> clientsToRemove = new HashSet<>();
ClientCallback clientCallback = new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId, new ChatMessage(userName, message, (withTime ? new Date() : null), game, color, messageType, soundToPlay));
List<UUID> chatUserIds = new ArrayList<>();
final Lock r = lock.readLock();
r.lock();
try {
chatUserIds.addAll(clients.keySet());
} finally {
r.unlock();
}
for (UUID userId : chatUserIds) {
Optional<User> user = managerFactory.userManager().getUser(userId);
if (user.isPresent()) {
user.get().fireCallback(clientCallback);
} else {
clientsToRemove.add(userId);
}
}
if (!clientsToRemove.isEmpty()) {
final Lock w = lock.readLock();
w.lock();
try {
clients.keySet().removeAll(clientsToRemove);
} finally {
w.unlock();
}
}
}
}
use of mage.view.ChatMessage in project mage by magefree.
the class LocalCommands method displayLocalCommandResponse.
private static void displayLocalCommandResponse(UUID chatId, String response) {
final String text = new StringBuilder().append("<font color=yellow>").append(response).append("</font>").toString();
ClientCallback chatMessage = new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId, new ChatMessage("", text, new Date(), null, ChatMessage.MessageColor.BLUE));
MageFrame.getInstance().processCallback(chatMessage);
}
Aggregations