mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
Fixed local server time in client's chat messages
This commit is contained in:
parent
bc3274b144
commit
ccd121277a
5 changed files with 23 additions and 17 deletions
|
@ -37,6 +37,8 @@ import java.awt.Color;
|
|||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -55,6 +57,11 @@ import org.mage.card.arcane.ManaSymbols;
|
|||
*/
|
||||
public class ChatPanelBasic extends javax.swing.JPanel {
|
||||
|
||||
/**
|
||||
* Time formatter
|
||||
*/
|
||||
protected final DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||
|
||||
protected UUID chatId;
|
||||
/**
|
||||
* Chat message color for opponents.
|
||||
|
@ -238,10 +245,10 @@ public class ChatPanelBasic extends javax.swing.JPanel {
|
|||
*/
|
||||
Pattern cardNamePattern = Pattern.compile(".*<font bgcolor=orange.*?</font>.*");
|
||||
|
||||
public void receiveMessage(String username, String message, String time, MessageType messageType, MessageColor color) {
|
||||
public void receiveMessage(String username, String message, Date time, MessageType messageType, MessageColor color) {
|
||||
StringBuilder text = new StringBuilder();
|
||||
if (time != null) {
|
||||
text.append(getColoredText(TIMESTAMP_COLOR, time + ": "));
|
||||
text.append(getColoredText(TIMESTAMP_COLOR, timeFormatter.format(time) + ": "));
|
||||
//this.txtConversation.append(TIMESTAMP_COLOR, time + " ");
|
||||
}
|
||||
String userColor;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
package mage.client.chat;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.util.Date;
|
||||
|
||||
import mage.client.SessionHandler;
|
||||
import mage.client.components.ColorPane;
|
||||
|
@ -54,7 +55,7 @@ public class ChatPanelSeparated extends ChatPanelBasic {
|
|||
* @param color Preferred color. Not used.
|
||||
*/
|
||||
@Override
|
||||
public void receiveMessage(String username, String message, String time, ChatMessage.MessageType messageType, ChatMessage.MessageColor color) {
|
||||
public void receiveMessage(String username, String message, Date time, ChatMessage.MessageType messageType, ChatMessage.MessageColor color) {
|
||||
switch (messageType) {
|
||||
case TALK:
|
||||
case WHISPER_TO:
|
||||
|
@ -65,7 +66,7 @@ public class ChatPanelSeparated extends ChatPanelBasic {
|
|||
}
|
||||
StringBuilder text = new StringBuilder();
|
||||
if (time != null) {
|
||||
text.append(getColoredText(TIMESTAMP_COLOR, time + ": "));
|
||||
text.append(getColoredText(TIMESTAMP_COLOR, timeFormatter.format(time) + ": "));
|
||||
}
|
||||
String userColor;
|
||||
String textColor;
|
||||
|
|
|
@ -7,7 +7,6 @@ import mage.interfaces.callback.ClientCallback;
|
|||
import mage.interfaces.callback.ClientCallbackMethod;
|
||||
import mage.view.ChatMessage;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
import java.util.StringTokenizer;
|
||||
|
@ -15,8 +14,6 @@ import java.util.UUID;
|
|||
|
||||
public final class LocalCommands {
|
||||
|
||||
private static final DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||
|
||||
/**
|
||||
* Handler for commands that do not require server interaction, i.e settings etc
|
||||
* @param chatId
|
||||
|
@ -60,7 +57,7 @@ public final class LocalCommands {
|
|||
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, timeFormatter.format(new Date()), ChatMessage.MessageColor.BLUE));
|
||||
new ChatMessage("", text, new Date(), ChatMessage.MessageColor.BLUE));
|
||||
MageFrame.getInstance().processCallback(chatMessage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -38,7 +39,7 @@ public class ChatMessage implements Serializable {
|
|||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String username;
|
||||
private String time;
|
||||
private Date time;
|
||||
private String message;
|
||||
private MessageColor color;
|
||||
private SoundToPlay soundToPlay;
|
||||
|
@ -56,15 +57,15 @@ public class ChatMessage implements Serializable {
|
|||
PlayerLeft, PlayerQuitTournament, PlayerSubmittedDeck, PlayerWhispered
|
||||
}
|
||||
|
||||
public ChatMessage(String username, String message, String time, MessageColor color) {
|
||||
public ChatMessage(String username, String message, Date time, MessageColor color) {
|
||||
this(username, message, time, color, null);
|
||||
}
|
||||
|
||||
public ChatMessage(String username, String message, String time, MessageColor color, SoundToPlay soundToPlay) {
|
||||
public ChatMessage(String username, String message, Date time, MessageColor color, SoundToPlay soundToPlay) {
|
||||
this(username, message, time, color, MessageType.TALK, soundToPlay);
|
||||
}
|
||||
|
||||
public ChatMessage(String username, String message, String time, MessageColor color, MessageType messageType, SoundToPlay soundToPlay) {
|
||||
public ChatMessage(String username, String message, Date time, MessageColor color, MessageType messageType, SoundToPlay soundToPlay) {
|
||||
this.username = username;
|
||||
this.message = message;
|
||||
this.time = time;
|
||||
|
@ -93,7 +94,7 @@ public class ChatMessage implements Serializable {
|
|||
return username;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
public Date getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ public class ChatSession {
|
|||
|
||||
public boolean broadcastInfoToUser(User toUser, String message) {
|
||||
if (clients.containsKey(toUser.getId())) {
|
||||
toUser.fireCallback(new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId, new ChatMessage(null, message, timeFormatter.format(new Date()), MessageColor.BLUE, MessageType.USER_INFO, null)));
|
||||
toUser.fireCallback(new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId, new ChatMessage(null, message, new Date(), MessageColor.BLUE, MessageType.USER_INFO, null)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -120,10 +120,10 @@ public class ChatSession {
|
|||
public boolean broadcastWhisperToUser(User fromUser, User toUser, String message) {
|
||||
if (clients.containsKey(toUser.getId())) {
|
||||
toUser.fireCallback(new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId,
|
||||
new ChatMessage(fromUser.getName(), message, timeFormatter.format(new Date()), MessageColor.YELLOW, MessageType.WHISPER_FROM, SoundToPlay.PlayerWhispered)));
|
||||
new ChatMessage(fromUser.getName(), message, new Date(), MessageColor.YELLOW, MessageType.WHISPER_FROM, SoundToPlay.PlayerWhispered)));
|
||||
if (clients.containsKey(fromUser.getId())) {
|
||||
fromUser.fireCallback(new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId,
|
||||
new ChatMessage(toUser.getName(), message, timeFormatter.format(new Date()), MessageColor.YELLOW, MessageType.WHISPER_TO, null)));
|
||||
new ChatMessage(toUser.getName(), message, new Date(), MessageColor.YELLOW, MessageType.WHISPER_TO, null)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ public class ChatSession {
|
|||
public void broadcast(String userName, String message, MessageColor color, boolean withTime, MessageType messageType, SoundToPlay soundToPlay) {
|
||||
if (!message.isEmpty()) {
|
||||
Set<UUID> clientsToRemove = new HashSet<>();
|
||||
ClientCallback clientCallback = new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId, new ChatMessage(userName, message, (withTime ? timeFormatter.format(new Date()) : ""), color, messageType, soundToPlay));
|
||||
ClientCallback clientCallback = new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId, new ChatMessage(userName, message, (withTime ? new Date() : null), color, messageType, soundToPlay));
|
||||
List<UUID> chatUserIds = new ArrayList<>();
|
||||
final Lock r = lock.readLock();
|
||||
r.lock();
|
||||
|
|
Loading…
Reference in a new issue