Commit f2366fa3 by Jonathan Thomas

More fixes for regressions related to player message bubbles. Seperated…

More fixes for regressions related to player message bubbles. Seperated `generateCharacter()` and `generateMessage()` functions for simplicity
parent 68db47af
Pipeline #13208 passed with stages
in 2 minutes 6 seconds
...@@ -22,6 +22,7 @@ All notable changes to **CreatureChat** are documented in this file. The format ...@@ -22,6 +22,7 @@ All notable changes to **CreatureChat** are documented in this file. The format
- Removed "pirate" speaking style and a few <non-response> outputs - Removed "pirate" speaking style and a few <non-response> outputs
- Passive entities no longer emit damage particles when attacking, they emit custom attack particles - Passive entities no longer emit damage particles when attacking, they emit custom attack particles
- Protect now auto sets friendship to 1 (if <= 0), to prevent entity from attacking and protecting at the same time - Protect now auto sets friendship to 1 (if <= 0), to prevent entity from attacking and protecting at the same time
- Seperated `generateCharacter()` and `generateMessage()` functions for simplicity
### Fixed ### Fixed
- Fixed a regression caused by adding a "-forge" suffix to one of our builds - Fixed a regression caused by adding a "-forge" suffix to one of our builds
......
...@@ -101,8 +101,14 @@ public class ClientPackets { ...@@ -101,8 +101,14 @@ public class ClientPackets {
ClientPlayNetworking.registerGlobalReceiver(ServerPackets.PACKET_S2C_MESSAGE, (client, handler, buffer, responseSender) -> { ClientPlayNetworking.registerGlobalReceiver(ServerPackets.PACKET_S2C_MESSAGE, (client, handler, buffer, responseSender) -> {
// Read the data from the server packet // Read the data from the server packet
UUID entityId = UUID.fromString(buffer.readString()); UUID entityId = UUID.fromString(buffer.readString());
UUID playerId = UUID.fromString(buffer.readString()); String sendingPlayerIdStr = buffer.readString(32767);
String playerName = buffer.readString(32767); String senderPlayerName = buffer.readString(32767);
UUID senderPlayerId;
if (!sendingPlayerIdStr.isEmpty()) {
senderPlayerId = UUID.fromString(sendingPlayerIdStr);
} else {
senderPlayerId = null;
}
String message = buffer.readString(32767); String message = buffer.readString(32767);
int line = buffer.readInt(); int line = buffer.readInt();
String status_name = buffer.readString(32767); String status_name = buffer.readString(32767);
...@@ -110,23 +116,24 @@ public class ClientPackets { ...@@ -110,23 +116,24 @@ public class ClientPackets {
int friendship = buffer.readInt(); int friendship = buffer.readInt();
// Update the chat data manager on the client-side // Update the chat data manager on the client-side
String currentPlayerName = client.player.getDisplayName().toString();
client.execute(() -> { // Make sure to run on the client thread client.execute(() -> { // Make sure to run on the client thread
MobEntity entity = ClientEntityFinder.getEntityByUUID(client.world, entityId); MobEntity entity = ClientEntityFinder.getEntityByUUID(client.world, entityId);
if (entity != null) { if (entity != null) {
ChatDataManager chatDataManager = ChatDataManager.getClientInstance(); ChatDataManager chatDataManager = ChatDataManager.getClientInstance();
EntityChatData chatData = chatDataManager.getOrCreateChatData(entity.getUuidAsString(), playerName); EntityChatData chatData = chatDataManager.getOrCreateChatData(entity.getUuidAsString(), currentPlayerName);
if (!message.isEmpty()) { if (!message.isEmpty()) {
chatData.currentMessage = message; chatData.currentMessage = message;
} }
chatData.currentLineNumber = line; chatData.currentLineNumber = line;
chatData.status = ChatDataManager.ChatStatus.valueOf(status_name); chatData.status = ChatDataManager.ChatStatus.valueOf(status_name);
chatData.sender = ChatDataManager.ChatSender.valueOf(sender_name); chatData.sender = ChatDataManager.ChatSender.valueOf(sender_name);
PlayerData playerData = chatData.getPlayerData(playerName); PlayerData playerData = chatData.getPlayerData(currentPlayerName);
playerData.friendship = friendship; playerData.friendship = friendship;
if (chatData.sender == ChatDataManager.ChatSender.USER && chatData.status == ChatDataManager.ChatStatus.DISPLAY) { if (chatData.sender == ChatDataManager.ChatSender.USER && chatData.status == ChatDataManager.ChatStatus.DISPLAY) {
// Add player message to queue for rendering // Add player message to queue for rendering
PlayerMessageManager.addMessage(playerId, playerName, chatData.currentMessage, ChatDataManager.TICKS_TO_DISPLAY_USER_MESSAGE); PlayerMessageManager.addMessage(senderPlayerId, chatData.currentMessage, senderPlayerName, ChatDataManager.TICKS_TO_DISPLAY_USER_MESSAGE);
} }
// Play sound with volume based on distance (from player or entity) // Play sound with volume based on distance (from player or entity)
......
...@@ -12,7 +12,7 @@ public class PlayerMessageManager { ...@@ -12,7 +12,7 @@ public class PlayerMessageManager {
private static final ConcurrentHashMap<UUID, PlayerMessage> messages = new ConcurrentHashMap<>(); private static final ConcurrentHashMap<UUID, PlayerMessage> messages = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<UUID, Boolean> openChatUIs = new ConcurrentHashMap<>(); private static final ConcurrentHashMap<UUID, Boolean> openChatUIs = new ConcurrentHashMap<>();
public static void addMessage(UUID playerUUID, String playerName, String messageText, int ticks) { public static void addMessage(UUID playerUUID, String messageText, String playerName, int ticks) {
messages.put(playerUUID, new PlayerMessage(playerUUID.toString(), playerName, messageText, ticks)); messages.put(playerUUID, new PlayerMessage(playerUUID.toString(), playerName, messageText, ticks));
} }
......
...@@ -85,7 +85,7 @@ public class ChatDataManager { ...@@ -85,7 +85,7 @@ public class ChatDataManager {
LOGGER.info("Updated chat data from UUID (" + oldUUID + ") to UUID (" + newUUID + ")"); LOGGER.info("Updated chat data from UUID (" + oldUUID + ") to UUID (" + newUUID + ")");
// Broadcast to all players // Broadcast to all players
ServerPackets.BroadcastPacketMessage(data); ServerPackets.BroadcastPacketMessage(data, null);
} else { } else {
LOGGER.info("Unable to update chat data, UUID not found: " + oldUUID); LOGGER.info("Unable to update chat data, UUID not found: " + oldUUID);
} }
......
...@@ -315,7 +315,7 @@ public class ServerPackets { ...@@ -315,7 +315,7 @@ public class ServerPackets {
userMessageBuilder.append("They speak in '").append(userLanguage).append("' with a ").append(randomSpeakingStyle).append(" style."); userMessageBuilder.append("They speak in '").append(userLanguage).append("' with a ").append(randomSpeakingStyle).append(" style.");
LOGGER.info(userMessageBuilder.toString()); LOGGER.info(userMessageBuilder.toString());
chatData.generateMessage(userLanguage, player, "system-character", userMessageBuilder.toString(), false); chatData.generateCharacter(userLanguage, player, userMessageBuilder.toString(), false);
} }
public static void generate_chat(String userLanguage, EntityChatData chatData, ServerPlayerEntity player, MobEntity entity, String message, boolean is_auto_message) { public static void generate_chat(String userLanguage, EntityChatData chatData, ServerPlayerEntity player, MobEntity entity, String message, boolean is_auto_message) {
...@@ -325,11 +325,11 @@ public class ServerPackets { ...@@ -325,11 +325,11 @@ public class ServerPackets {
// Add new message // Add new message
LOGGER.info("Player message received: " + message + " | Entity: " + entity.getType().toString()); LOGGER.info("Player message received: " + message + " | Entity: " + entity.getType().toString());
chatData.generateMessage(userLanguage, player, "system-chat", message, is_auto_message); chatData.generateMessage(userLanguage, player, message, is_auto_message);
} }
// Send new message to all connected players // Send new message to all connected players
public static void BroadcastPacketMessage(EntityChatData chatData) { public static void BroadcastPacketMessage(EntityChatData chatData, ServerPlayerEntity sender) {
for (ServerWorld world : serverInstance.getWorlds()) { for (ServerWorld world : serverInstance.getWorlds()) {
UUID entityId = UUID.fromString(chatData.entityId); UUID entityId = UUID.fromString(chatData.entityId);
MobEntity entity = (MobEntity)ServerEntityFinder.getEntityByUUID(world, entityId); MobEntity entity = (MobEntity)ServerEntityFinder.getEntityByUUID(world, entityId);
...@@ -351,8 +351,13 @@ public class ServerPackets { ...@@ -351,8 +351,13 @@ public class ServerPackets {
// Write the entity's chat updated data // Write the entity's chat updated data
buffer.writeString(chatData.entityId); buffer.writeString(chatData.entityId);
buffer.writeString(player.getUuidAsString()); if (sender != null) {
buffer.writeString(player.getDisplayName().getString()); buffer.writeString(sender.getUuidAsString());
buffer.writeString(sender.getDisplayName().toString());
} else {
buffer.writeString("");
buffer.writeString("Unknown");
}
buffer.writeString(chatData.currentMessage); buffer.writeString(chatData.currentMessage);
buffer.writeInt(chatData.currentLineNumber); buffer.writeInt(chatData.currentLineNumber);
buffer.writeString(chatData.status.toString()); buffer.writeString(chatData.status.toString());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment