diff --git a/src/main/java/jesse/keeblarcraft/Commands/CustomCommandManager.java b/src/main/java/jesse/keeblarcraft/Commands/CustomCommandManager.java index a11bf9b..e28c075 100644 --- a/src/main/java/jesse/keeblarcraft/Commands/CustomCommandManager.java +++ b/src/main/java/jesse/keeblarcraft/Commands/CustomCommandManager.java @@ -8,31 +8,12 @@ package jesse.keeblarcraft.Commands; -import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.Text; - public class CustomCommandManager { // Intentionally empty constructor since at object definition time it may not be possible to register commands public CustomCommandManager() {} - // Registers all commands for the mod + // Registers all custom command classes here public void RegisterCustomCommands() { - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { - dispatcher.register(CommandManager.literal("amogus").executes(ctx -> { - ctx.getSource().sendFeedback(() -> Text.literal("AMOGOOOOOO"), false); - return 0; - })); - }); - - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { - dispatcher.register(CommandManager.literal("cbtest").executes(ctx -> { - ctx.getSource().sendFeedback(() -> TestCallback(ctx.getSource()), false); - return 0; - })); - }); - // CUSTOM COMMAND CLASS OBJECTS BELOW ShortcutCommands shortcuts = new ShortcutCommands(); NoteCommands noteCommands = new NoteCommands(); @@ -41,11 +22,5 @@ public class CustomCommandManager { System.out.println("REGISTERING CUSTOM COMMAND EXTENSIONS BELOW"); shortcuts.RegisterShortcutCommands(); noteCommands.RegisterNoteCommands(); - - } - - public Text TestCallback(ServerCommandSource ctx) { - String stuff = ctx.getName(); - return Text.literal("Callback called from " + stuff); } } diff --git a/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java b/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java index b23785f..8000a42 100644 --- a/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java +++ b/src/main/java/jesse/keeblarcraft/ConfigMgr/ConfigManager.java @@ -133,8 +133,22 @@ public class ConfigManager { // GetJsonStringFromFile // // Retrieves a json formatted string from the file based on key. Returns empty string if not found - public String GetJsonStringFromFile(String fileName, String key) { - String ret = ""; + public Object GetJsonObjectFromFile(String key, String fileName, Object jsonObject) { + Object ret = jsonObject.getClass(); + Gson gson = new Gson(); + // Step 1: Get file as 1 constant string + try { + File file = new File(fileName); + if (file.exists()) { + String str = file.toString(); + ret = gson.fromJson(str, jsonObject.getClass()); + } else { + System.out.println("File does not exist. Cannot convert to json"); + } + + } catch (Exception e) { + System.out.println("Something went wrong when converting json file object to object"); + } return ret; } diff --git a/src/main/java/jesse/keeblarcraft/JsonClassObjects/PlayerNote.java b/src/main/java/jesse/keeblarcraft/JsonClassObjects/PlayerNote.java new file mode 100644 index 0000000..2294ab9 --- /dev/null +++ b/src/main/java/jesse/keeblarcraft/JsonClassObjects/PlayerNote.java @@ -0,0 +1,59 @@ +/* + * + * Note.java + * + * Class defines what will be in a configuration file for a user note. All metadata is in this class when read from file +*/ + +package jesse.keeblarcraft.JsonClassObjects; + +import java.util.HashMap; +import java.util.Map.Entry; + +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 noteMap = new HashMap(); + } + + NoteFile thisNote = new NoteFile(); + ConfigManager config = new ConfigManager(); + + public PlayerNote(String uuid) { + /// TODO: Below code needs to be tested first + thisNote = (NoteFile) config.GetJsonObjectFromFile(uuid, uuid, NoteFile.class); + } + + public void AddNote(String newNote) { + Integer noteKey = thisNote.noteMap.size() + 1; + thisNote.noteMap.put(noteKey, newNote); + } + + public void DeleteNote(Integer noteId) { + thisNote.noteMap.remove(noteId); + } + + public void ModifyNote(Integer noteId, String newNote) { + thisNote.noteMap.put(noteId, newNote); + } + + // 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) { + Integer ret = -1; + for (Entry entry : thisNote.noteMap.entrySet()) { + if (entry.getValue().equals(note)) { + ret = entry.getKey(); + } + } + + return ret; + } +} diff --git a/src/main/java/jesse/keeblarcraft/Keeblarcraft.java b/src/main/java/jesse/keeblarcraft/Keeblarcraft.java index b18a000..856caa4 100644 --- a/src/main/java/jesse/keeblarcraft/Keeblarcraft.java +++ b/src/main/java/jesse/keeblarcraft/Keeblarcraft.java @@ -36,20 +36,25 @@ public class Keeblarcraft implements ModInitializer { // This code runs as soon as Minecraft is in a mod-load-ready state. // However, some things (like resources) may still be uninitialized. // Proceed with mild caution. - LOGGER.info("Hello Fabric world!"); - cmdMgr.RegisterCustomCommands(); if (setup != null) { try { + // Run setup. If setup fails; it throws SETUP_FAILED_EXCEPTION + LOGGER.info("Running setup stage"); setup.RunSetup(); + + // Run command registrations from the command manager + LOGGER.info("Running command registration"); + cmdMgr.RegisterCustomCommands(); + } catch (SETUP_FAILED_EXCEPTION e) { System.out.println("ERROR. Setup failed to initialize environment. Mod likely does not have read/write permissions inside area. Mod will now close out."); e.printStackTrace(); } } else { // Program exit. Dual definition of setup somehow happened! - System.out.println("Dual definition of singleton attempted! Out of order initialization?"); + System.out.println("Dual definition of singleton attempted! Out of order initialization? How did this even happen?"); } } } \ No newline at end of file