the_big_one/src/main/java/jesse/keeblarcraft/Commands/NoteCommands.java

149 lines
6.0 KiB
Java
Raw Normal View History

package jesse.keeblarcraft.Commands;
import java.util.UUID;
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.JsonClassObjects.PlayerNote;
import jesse.keeblarcraft.Utils.ChatUtil;
import jesse.keeblarcraft.Utils.CustomExceptions.DIRECTORY_CREATE_EXCEPTION;
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 = "notes"; // 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
try {
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!! Either the directory already exists or we are missing permissions!"); //TODO: Critical failure
}
} catch (DIRECTORY_CREATE_EXCEPTION e) {
System.out.println("Directory creation failed");
}
} 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 Integer AddNote(String value, CommandContext<ServerCommandSource> context) {
Integer ret = -1;
if (context.getSource().isExecutedByPlayer()) {
ServerPlayerEntity player = context.getSource().getPlayer();
// Note mgmt
PlayerNote note = new PlayerNote(player.getUuidAsString());
note.AddNote(value, 1, 1, 1, 1);
ChatUtil.SendPlayerMsg(player, "New note logged to entry! View notes any time with /notegui");
ret = 0;
} else {
System.out.println("Only a player can execute this command!");
}
return ret;
}
private int DeleteNote(int value, CommandContext<ServerCommandSource> context) {
int ret = -1;
return ret;
}
private int ModifyNote(int value, CommandContext<ServerCommandSource> context) {
int ret = -1;
return ret;
}
private int PurgeAllNotes(String value, CommandContext<ServerCommandSource> context) {
int ret = -1;
return ret;
}
private int ListNotes(String value, CommandContext<ServerCommandSource> context) {
int ret = -1;
return ret;
}
private int OpenNoteGui(String value, CommandContext<ServerCommandSource> context) {
int ret = -1;
return ret;
}
private int FilterForNote(String value, CommandContext<ServerCommandSource> context) {
int ret = -1;
return ret;
}
}