added player note stuff. UNTESTED
This commit is contained in:
parent
3507b7e69a
commit
49961bba71
13
src/main/java/jesse/keeblarcraft/GuiMgr/GuiMgr.java
Normal file
13
src/main/java/jesse/keeblarcraft/GuiMgr/GuiMgr.java
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
*
|
||||
* GuiMgr
|
||||
*
|
||||
* Handles everything related to in-game gui environments
|
||||
*
|
||||
*/
|
||||
|
||||
package jesse.keeblarcraft.GuiMgr;
|
||||
|
||||
public class GuiMgr {
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
// Integer = note id
|
||||
// String = note
|
||||
public HashMap<Integer, String> noteMap = new HashMap<Integer, String>();
|
||||
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;
|
||||
}
|
||||
|
||||
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<Integer, NoteMetadata> noteMap = new HashMap<Integer, NoteMetadata>();
|
||||
}
|
||||
|
||||
|
||||
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<Integer, String> entry : thisNote.noteMap.entrySet()) {
|
||||
if (entry.getValue().equals(note)) {
|
||||
for (Entry<Integer, NoteMetadata> entry : thisNote.noteMap.entrySet()) {
|
||||
if (entry.getValue().note.equals(currentNote)) {
|
||||
ret = entry.getKey();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user