mirror of
https://github.com/correl/mage.git
synced 2024-11-15 03:00:16 +00:00
* Chat time - Fixed a bug that the chat time was not updated.
This commit is contained in:
parent
984792b2c4
commit
926210a159
2 changed files with 6 additions and 37 deletions
|
@ -41,7 +41,6 @@ import java.util.EnumMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import javax.print.attribute.standard.MediaSize;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.table.JTableHeader;
|
||||
|
@ -202,6 +201,7 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
* @param username message sender
|
||||
* @param message message itself
|
||||
* @param time timestamp
|
||||
* @param messageType
|
||||
* @param color Preferred color. Not used.
|
||||
*/
|
||||
public void receiveMessage(String username, String message, String time, MessageType messageType, MessageColor color) {
|
||||
|
@ -449,38 +449,10 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
// public void setPlayers(Collection<String> players) {
|
||||
public void setPlayers(List<Collection<UsersView>> view) {
|
||||
try {
|
||||
// TODO: sort by user name
|
||||
tableModel.loadData(view.get(0));
|
||||
} catch (Exception ex) {
|
||||
this.players.clear();
|
||||
}
|
||||
|
||||
// if (players != null) {
|
||||
// boolean update;
|
||||
// int size = players.size();
|
||||
// List<String> list = new ArrayList<String>(players);
|
||||
// Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
|
||||
// if (size != this.players.size()) {
|
||||
// update = true;
|
||||
// } else {
|
||||
// update = false;
|
||||
// for (int i = 0; i < size; i++) {
|
||||
// if (!list.get(i).equals(this.players.get(i))) {
|
||||
// update = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (update) {
|
||||
// synchronized (tableModel) {
|
||||
// this.players = list;
|
||||
// tableModel.loadData(this.players);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// this.players.clear();
|
||||
// }
|
||||
}
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JScrollPane jScrollPanePlayers;
|
||||
|
|
|
@ -30,8 +30,7 @@ package mage.server;
|
|||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
|
@ -48,8 +47,6 @@ import org.apache.log4j.Logger;
|
|||
public class ChatSession {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ChatSession.class);
|
||||
private static final Calendar cal = new GregorianCalendar();
|
||||
|
||||
private ConcurrentHashMap<UUID, String> clients = new ConcurrentHashMap<UUID, String>();
|
||||
private UUID chatId;
|
||||
private DateFormat timeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);
|
||||
|
@ -90,7 +87,7 @@ public class ChatSession {
|
|||
|
||||
public boolean broadcastInfoToUser(User toUser, String message) {
|
||||
if (clients.containsKey(toUser.getId())) {
|
||||
toUser.fireCallback(new ClientCallback("chatMessage", chatId, new ChatMessage(null, message, timeFormatter.format(cal.getTime()), MessageColor.ORANGE, MessageType.USER_INFO, null)));
|
||||
toUser.fireCallback(new ClientCallback("chatMessage", chatId, new ChatMessage(null, message, timeFormatter.format(new Date()), MessageColor.ORANGE, MessageType.USER_INFO, null)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -99,10 +96,10 @@ public class ChatSession {
|
|||
public boolean broadcastWhisperToUser(User fromUser, User toUser, String message) {
|
||||
if (clients.containsKey(toUser.getId())) {
|
||||
toUser.fireCallback(new ClientCallback("chatMessage", chatId,
|
||||
new ChatMessage(new StringBuilder("Whisper from ").append(fromUser.getName()).toString(), message, timeFormatter.format(cal.getTime()), MessageColor.YELLOW, MessageType.WHISPER, SoundToPlay.PlayerWhispered)));
|
||||
new ChatMessage(new StringBuilder("Whisper from ").append(fromUser.getName()).toString(), message, timeFormatter.format(new Date()), MessageColor.YELLOW, MessageType.WHISPER, SoundToPlay.PlayerWhispered)));
|
||||
if (clients.containsKey(fromUser.getId())) {
|
||||
fromUser.fireCallback(new ClientCallback("chatMessage", chatId,
|
||||
new ChatMessage(new StringBuilder("Whisper to ").append(toUser.getName()).toString(), message, timeFormatter.format(cal.getTime()), MessageColor.YELLOW, MessageType.WHISPER, null)));
|
||||
new ChatMessage(new StringBuilder("Whisper to ").append(toUser.getName()).toString(), message, timeFormatter.format(new Date()), MessageColor.YELLOW, MessageType.WHISPER, null)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +121,7 @@ public class ChatSession {
|
|||
public void broadcast(String userName, String message, MessageColor color, boolean withTime, MessageType messageType, SoundToPlay soundToPlay) {
|
||||
if (!message.isEmpty()) {
|
||||
final String msg = message;
|
||||
final String time = (withTime ? timeFormatter.format(cal.getTime()):"");
|
||||
final String time = (withTime ? timeFormatter.format(new Date()):"");
|
||||
final String username = userName;
|
||||
logger.debug("Broadcasting '" + msg + "' for " + chatId);
|
||||
for (UUID userId: clients.keySet()) {
|
||||
|
|
Loading…
Reference in a new issue