package jesse.keeblarcraft.Commands; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.context.CommandContext; import com.mojang.datafixers.Products.P1; import jesse.keeblarcraft.ConfigMgr.ConfigManager; import jesse.keeblarcraft.Utils.ChatUtil; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; public class NoteCommands { // IMPORTANT NOTE: // // Each player will retain their own private file of notes inside a "notes" directory inside the overall mod config directory ConfigManager notesConfig = new ConfigManager(); String NOTES_GLOBAL_DIRECTORY = ""; // The overall "notes" dir inside cfg folder public NoteCommands() { // Check if directory exists if (notesConfig.DoesDirectoryExist(NOTES_GLOBAL_DIRECTORY) == false) { // Attempt to create the directory if (notesConfig.CreateDirectory(NOTES_GLOBAL_DIRECTORY) == true) { System.out.println("Created notes directory successfully!"); //TODO: Success! } else { System.out.println("ERROR: Notes directory FAILED to create!! Permissions missing to create directory!"); //TODO: Critical failure } } else { System.out.println("Notes directory already exists. Skipping creation..."); //TODO: Success! } } public void RegisterNoteCommands() { // Command: "/addnote note goes here" CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { dispatcher.register(CommandManager.literal("addnote") .then(CommandManager.argument("value", StringArgumentType.greedyString()) .executes(context -> AddNote(StringArgumentType.getString(context, "value"), context)))); }); // Command: "/delnote noteIdHere" // CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { // dispatcher.register(CommandManager.literal("delnote") // .then(CommandManager.argument("value", StringArgumentType.greedyString()) // .executes(context -> AddNote(StringArgumentType.getString(context, "value"), context)))); // }); // Command: "/purgenotes" CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { dispatcher.register(CommandManager.literal("purgenotes") .then(CommandManager.argument("value", StringArgumentType.greedyString()) .executes(context -> PurgeAllNotes(StringArgumentType.getString(context, "value"), context)))); }); // Command: "/modifynote noteIdHere" CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { dispatcher.register(CommandManager.literal("editnote") .then(CommandManager.argument("value", IntegerArgumentType.integer()) .executes(context -> ModifyNote(IntegerArgumentType.getInteger(context, "value"), context)))); }); // Command Root: "/delnote noteIdHere" // Aliases: "/rmnote", "/deletenote" CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { final var rootDeleteCmd = dispatcher.register(CommandManager.literal("delnote") .then(CommandManager.argument("value", IntegerArgumentType.integer()) .executes(context -> DeleteNote(IntegerArgumentType.getInteger(context, "value"), context)))); // Alias redirects dispatcher.register(CommandManager.literal("rmnote").redirect(rootDeleteCmd)); dispatcher.register(CommandManager.literal("deletenote").redirect(rootDeleteCmd)); }); } /// COMMAND HANDLERS BELOW // AddNote // // Adds a new note based on the string value provided by the player. The note is labeled in the background based on the portion // of the story they are currently in as well to help provide filtering methods later on private int AddNote(String value, CommandContext context) { int ret = -1; if (context.getSource().isExecutedByPlayer()) { ServerPlayerEntity player = context.getSource().getPlayer(); notesConfig.AddToKey(player.getUuidAsString(), value); ChatUtil.SendPlayerMsg(player, "New note logged to entry! View notes any time with /notegui"); } else { System.out.println("Only a player can execute this command!"); } return ret; } private int DeleteNote(int value, CommandContext context) { int ret = -1; return ret; } private int ModifyNote(int value, CommandContext context) { int ret = -1; return ret; } private int PurgeAllNotes(String value, CommandContext context) { int ret = -1; return ret; } private int ListNotes(String value, CommandContext context) { int ret = -1; return ret; } private int OpenNoteGui(String value, CommandContext context) { int ret = -1; return ret; } private int FilterForNote(String value, CommandContext context) { int ret = -1; return ret; } }