From 49961bba711080df4b4d69897dd0e988c19738cd Mon Sep 17 00:00:00 2001 From: jkibbels Date: Fri, 2 Aug 2024 16:02:25 -0400 Subject: [PATCH] added player note stuff. UNTESTED --- .../jesse/keeblarcraft/GuiMgr/GuiMgr.java | 13 ++++ .../JsonClassObjects/PlayerNote.java | 72 +++++++++++++++---- 2 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 src/main/java/jesse/keeblarcraft/GuiMgr/GuiMgr.java diff --git a/src/main/java/jesse/keeblarcraft/GuiMgr/GuiMgr.java b/src/main/java/jesse/keeblarcraft/GuiMgr/GuiMgr.java new file mode 100644 index 0000000..d70d04c --- /dev/null +++ b/src/main/java/jesse/keeblarcraft/GuiMgr/GuiMgr.java @@ -0,0 +1,13 @@ +/* + * + * GuiMgr + * + * Handles everything related to in-game gui environments + * +*/ + +package jesse.keeblarcraft.GuiMgr; + +public class GuiMgr { + +} diff --git a/src/main/java/jesse/keeblarcraft/JsonClassObjects/PlayerNote.java b/src/main/java/jesse/keeblarcraft/JsonClassObjects/PlayerNote.java index 2294ab9..828dba5 100644 --- a/src/main/java/jesse/keeblarcraft/JsonClassObjects/PlayerNote.java +++ b/src/main/java/jesse/keeblarcraft/JsonClassObjects/PlayerNote.java @@ -7,6 +7,7 @@ package jesse.keeblarcraft.JsonClassObjects; +import java.math.BigInteger; import java.util.HashMap; import java.util.Map.Entry; @@ -15,41 +16,88 @@ import jesse.keeblarcraft.ConfigMgr.ConfigManager; public class PlayerNote { // Internal class structure that defines a blank note. It represents the overall loaded json object - public class NoteFile { - public String uuid; + private class NoteMetadata { + public NoteMetadata(String note, long id, long mcday, long sysTime, long chapter, long part) { + this.note = note; + this.noteId = id; + this.minecraftDay = mcday; + this.systemTime = sysTime; + this.storyChapter = chapter; + this.storyPart = part; + } - // Integer = note id - // String = note - public HashMap noteMap = new HashMap(); + String note; // The note itself + + long noteId; // Copied in from the file name, noteId + long minecraftDay; // The minecraft day the note was taken on + long systemTime; // The current system time of the server + long storyChapter; // The chapter of the story the player is in + long storyPart; // Every event in a story is one part } + public class NoteFile { + // Players uuid is the name of the file + String uuid; + + // Contents of file + /* + * Example: + * player_uuid_here: + * { + * "1": + * { + * "note": "this is the players first note"; + * "noteId": "1"; + * "minecraftDay": "443"; + * "systemTime": "4849892839823"; + * "storyChapter": "3"; + * "storyPart": "2"; + * } + * "2": + * { + * Etc. + * } + * } + */ + public HashMap noteMap = new HashMap(); + } + + NoteFile thisNote = new NoteFile(); ConfigManager config = new ConfigManager(); public PlayerNote(String uuid) { /// TODO: Below code needs to be tested first + /// TODO: It's possible the below code may prove to be incredibly slow on large files and should probably + /// TODO: introduce a secondary load method where it only finds the file pointer and doesn't bother returning file contents as well thisNote = (NoteFile) config.GetJsonObjectFromFile(uuid, uuid, NoteFile.class); + + // It's possible the above code will return a blank class if a file doesn't exist. This will make + // a new file with this players uuid + if ("".equals(thisNote.uuid)) { + thisNote.uuid = uuid; + } } - public void AddNote(String newNote) { + public void AddNote(String newNote, long minecraftDay, long systemTime, long storyChapter, long storyPart) { Integer noteKey = thisNote.noteMap.size() + 1; - thisNote.noteMap.put(noteKey, newNote); + thisNote.noteMap.put(noteKey, new NoteMetadata(newNote, noteKey, minecraftDay, systemTime, storyChapter, storyPart)); } public void DeleteNote(Integer noteId) { thisNote.noteMap.remove(noteId); } - public void ModifyNote(Integer noteId, String newNote) { - thisNote.noteMap.put(noteId, newNote); + public void ModifyNote(Integer noteId, String newNote, long minecraftDay, long systemTime, long storyChapter, long storyPart) { + thisNote.noteMap.put(noteId, new NoteMetadata(newNote, noteId, minecraftDay, systemTime, storyChapter, storyPart)); } // Find the key of a note if it exists (O(n) search time) // Returns -1 on failure to find note key - public Integer GetNoteKey(String note) { + public Integer GetNoteKey(String currentNote) { Integer ret = -1; - for (Entry entry : thisNote.noteMap.entrySet()) { - if (entry.getValue().equals(note)) { + for (Entry entry : thisNote.noteMap.entrySet()) { + if (entry.getValue().note.equals(currentNote)) { ret = entry.getKey(); } }