Commit 011ddb99 by Jonathan Thomas

Additional refactor around playerData and friendship and player messages -…

Additional refactor around playerData and friendship and player messages - trying to fix an issue with friendship not updating correctly
parent f2366fa3
Pipeline #13209 passed with stages
in 2 minutes 6 seconds
......@@ -112,33 +112,45 @@ public class ClientPackets {
String message = buffer.readString(32767);
int line = buffer.readInt();
String status_name = buffer.readString(32767);
ChatDataManager.ChatStatus status = ChatDataManager.ChatStatus.valueOf(status_name);
String sender_name = buffer.readString(32767);
ChatDataManager.ChatSender sender = ChatDataManager.ChatSender.valueOf(sender_name);
int friendship = buffer.readInt();
String currentPlayerName = client.player.getDisplayName().getString();
// 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
MobEntity entity = ClientEntityFinder.getEntityByUUID(client.world, entityId);
if (entity != null) {
ChatDataManager chatDataManager = ChatDataManager.getClientInstance();
EntityChatData chatData = chatDataManager.getOrCreateChatData(entity.getUuidAsString(), currentPlayerName);
if (entity == null) {
return;
}
// Get entity chat data for current entity & player
ChatDataManager chatDataManager = ChatDataManager.getClientInstance();
EntityChatData chatData = chatDataManager.getOrCreateChatData(entity.getUuidAsString(), currentPlayerName);
if (senderPlayerId != null && sender == ChatDataManager.ChatSender.USER && status == ChatDataManager.ChatStatus.DISPLAY) {
// Add player message to queue for rendering
PlayerMessageManager.addMessage(senderPlayerId, message, senderPlayerName, ChatDataManager.TICKS_TO_DISPLAY_USER_MESSAGE);
chatData.status = ChatDataManager.ChatStatus.PENDING;
} else {
// Add entity message
if (!message.isEmpty()) {
chatData.currentMessage = message;
}
chatData.currentLineNumber = line;
chatData.status = ChatDataManager.ChatStatus.valueOf(status_name);
chatData.sender = ChatDataManager.ChatSender.valueOf(sender_name);
PlayerData playerData = chatData.getPlayerData(currentPlayerName);
playerData.friendship = friendship;
if (chatData.sender == ChatDataManager.ChatSender.USER && chatData.status == ChatDataManager.ChatStatus.DISPLAY) {
// Add player message to queue for rendering
PlayerMessageManager.addMessage(senderPlayerId, chatData.currentMessage, senderPlayerName, ChatDataManager.TICKS_TO_DISPLAY_USER_MESSAGE);
}
chatData.status = status;
chatData.sender = sender;
// Play sound with volume based on distance (from player or entity)
playNearbyUISound(client, entity, 0.2f);
if (senderPlayerId != null) {
PlayerData playerData = chatData.getPlayerData(senderPlayerName);
playerData.friendship = friendship;
}
}
// Play sound with volume based on distance (from player or entity)
playNearbyUISound(client, entity, 0.2f);
});
});
......
......@@ -484,16 +484,8 @@ public class BubbleRenderer {
playerData = chatData.getPlayerData(player.getDisplayName().getString());
}
} else if (entity instanceof PlayerEntity) {
PlayerEntity playerEntity = (PlayerEntity) entity;
chatData = PlayerMessageManager.getMessage(entity.getUuid());
if (chatData != null) {
playerData = chatData.getPlayerData(playerEntity.getDisplayName().getString());
}
}
// Don't allow a null playerData
if (playerData == null) {
playerData = new PlayerData();
playerData = new PlayerData(); // no friendship needed for player messages
}
float minTextHeight = (ChatDataManager.DISPLAY_NUM_LINES * (fontRenderer.fontHeight + lineSpacing)) + (DISPLAY_PADDING * 2);
......
......@@ -353,7 +353,7 @@ public class ServerPackets {
buffer.writeString(chatData.entityId);
if (sender != null) {
buffer.writeString(sender.getUuidAsString());
buffer.writeString(sender.getDisplayName().toString());
buffer.writeString(sender.getDisplayName().getString());
} else {
buffer.writeString("");
buffer.writeString("Unknown");
......
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