Commit e1c3ea8d by Jonathan Thomas

Separating client & server instances of ChatDataManager, in preparation for data sync

parent bfe50738
......@@ -106,7 +106,7 @@ public class ClickHandler {
// Handle the click for the closest entity after the loop
if (closestEntity != null) {
// Look-up conversation
ChatDataManager.EntityChatData chatData = ChatDataManager.getInstance().getOrCreateChatData(closestEntity.getId());
ChatDataManager.EntityChatData chatData = ChatDataManager.getClientInstance().getOrCreateChatData(closestEntity.getId());
if (chatData.currentMessage.isEmpty()) {
// Start conversation
......
......@@ -167,7 +167,7 @@ public class ClientInit implements ClientModInitializer {
}
// Look-up greeting (if any)
ChatDataManager.EntityChatData chatData = ChatDataManager.getInstance().getOrCreateChatData(entity.getId());
ChatDataManager.EntityChatData chatData = ChatDataManager.getClientInstance().getOrCreateChatData(entity.getId());
List<String> lines = chatData.getWrappedLines();
// Set the range of lines to display
......
......@@ -7,7 +7,8 @@ import java.util.ArrayList;
public class ChatDataManager {
// Use a static instance to manage our data globally
private static final ChatDataManager INSTANCE = new ChatDataManager();
private static final ChatDataManager SERVER_INSTANCE = new ChatDataManager();
private static final ChatDataManager CLIENT_INSTANCE = new ChatDataManager();
public static int MAX_CHAR_PER_LINE = 22;
public enum ChatStatus {
......@@ -77,9 +78,14 @@ public class ChatDataManager {
entityChatDataMap = new HashMap<>();
}
// Method to get the global instance of the data manager
public static ChatDataManager getInstance() {
return INSTANCE;
// Method to get the global instance of the server data manager
public static ChatDataManager getServerInstance() {
return SERVER_INSTANCE;
}
// Method to get the global instance of the client data manager (synced from server)
public static ChatDataManager getClientInstance() {
return CLIENT_INSTANCE;
}
// Retrieve chat data for a specific entity, or create it if it doesn't exist
......
......@@ -36,7 +36,7 @@ public class ModInit implements ModInitializer {
// Slow entity
SlowEntity((LivingEntity) entity, 3.5F);
ChatDataManager.EntityChatData chatData = ChatDataManager.getInstance().getOrCreateChatData(entityId);
ChatDataManager.EntityChatData chatData = ChatDataManager.getServerInstance().getOrCreateChatData(entityId);
if (chatData.status == ChatDataManager.ChatStatus.NONE ||
chatData.status == ChatDataManager.ChatStatus.END) {
// Only generate a new greeting if not already doing so
......@@ -61,7 +61,7 @@ public class ModInit implements ModInitializer {
// Slow entity
SlowEntity((LivingEntity) entity, 3.5F);
ChatDataManager.EntityChatData chatData = ChatDataManager.getInstance().getOrCreateChatData(entityId);
ChatDataManager.EntityChatData chatData = ChatDataManager.getServerInstance().getOrCreateChatData(entityId);
if (chatData.status == ChatDataManager.ChatStatus.DISPLAY) {
// Only set line number if status allows
LOGGER.info("Increment read lines to " + lineNumber + " for: " + entity.getType().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