added player note stuff. UNTESTED

This commit is contained in:
jkibbels 2024-08-02 16:02:25 -04:00
parent 3507b7e69a
commit 49961bba71
2 changed files with 73 additions and 12 deletions

View File

@ -0,0 +1,13 @@
/*
*
* GuiMgr
*
* Handles everything related to in-game gui environments
*
*/
package jesse.keeblarcraft.GuiMgr;
public class GuiMgr {
}

View File

@ -7,6 +7,7 @@
package jesse.keeblarcraft.JsonClassObjects; package jesse.keeblarcraft.JsonClassObjects;
import java.math.BigInteger;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -15,41 +16,88 @@ import jesse.keeblarcraft.ConfigMgr.ConfigManager;
public class PlayerNote { public class PlayerNote {
// Internal class structure that defines a blank note. It represents the overall loaded json object // Internal class structure that defines a blank note. It represents the overall loaded json object
public class NoteFile { private class NoteMetadata {
public String uuid; 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; // The note itself
// String = note
public HashMap<Integer, String> noteMap = new HashMap<Integer, String>(); 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<Integer, NoteMetadata> noteMap = new HashMap<Integer, NoteMetadata>();
}
NoteFile thisNote = new NoteFile(); NoteFile thisNote = new NoteFile();
ConfigManager config = new ConfigManager(); ConfigManager config = new ConfigManager();
public PlayerNote(String uuid) { public PlayerNote(String uuid) {
/// TODO: Below code needs to be tested first /// 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); 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; 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) { public void DeleteNote(Integer noteId) {
thisNote.noteMap.remove(noteId); thisNote.noteMap.remove(noteId);
} }
public void ModifyNote(Integer noteId, String newNote) { public void ModifyNote(Integer noteId, String newNote, long minecraftDay, long systemTime, long storyChapter, long storyPart) {
thisNote.noteMap.put(noteId, newNote); 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) // Find the key of a note if it exists (O(n) search time)
// Returns -1 on failure to find note key // Returns -1 on failure to find note key
public Integer GetNoteKey(String note) { public Integer GetNoteKey(String currentNote) {
Integer ret = -1; Integer ret = -1;
for (Entry<Integer, String> entry : thisNote.noteMap.entrySet()) { for (Entry<Integer, NoteMetadata> entry : thisNote.noteMap.entrySet()) {
if (entry.getValue().equals(note)) { if (entry.getValue().note.equals(currentNote)) {
ret = entry.getKey(); ret = entry.getKey();
} }
} }