From 091ce4c72c123f43f317c097818ace15f3a085fa Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Wed, 10 Aug 2022 10:15:01 +0200 Subject: Profile command (#88) * e * omg finish profile shit * api and fix 1.12.2 preprocess * fix class names --- .../internal/command/OneConfigCommand.java | 82 ++++++++++++++++++++-- 1 file changed, 78 insertions(+), 4 deletions(-) (limited to 'src/main/java/cc/polyfrost/oneconfig/internal/command') diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java b/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java index c93831b..3c1aebb 100644 --- a/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java +++ b/src/main/java/cc/polyfrost/oneconfig/internal/command/OneConfigCommand.java @@ -26,13 +26,15 @@ package cc.polyfrost.oneconfig.internal.command; +import cc.polyfrost.oneconfig.internal.config.OneConfigConfig; +import cc.polyfrost.oneconfig.internal.config.profiles.Profiles; import cc.polyfrost.oneconfig.internal.gui.HudGui; import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.libs.universal.ChatColor; +import cc.polyfrost.oneconfig.libs.universal.UChat; +import cc.polyfrost.oneconfig.utils.commands.annotations.*; import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import cc.polyfrost.oneconfig.utils.InputUtils; -import cc.polyfrost.oneconfig.utils.commands.annotations.Command; -import cc.polyfrost.oneconfig.utils.commands.annotations.Main; -import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; /** * The main OneConfig command. @@ -57,8 +59,80 @@ public class OneConfigCommand { private static class DestroySubCommand { @Main private static void main() { - OneConfigGui.instanceToRestore = null; + OneConfigGui.INSTANCE = null; InputUtils.stopBlockingInput(); } } + + @SubCommand(value = "profile", description = "Actions related to profiles.", aliases = {"profiles"}) + private static class ProfileSubCommand { + @SubCommand(value = "list", description = "View all profiles", aliases = {"view"}) + private static class List { + @Main + private static void main() { + StringBuilder builder = new StringBuilder() + .append(ChatColor.GOLD).append("Available profiles:"); + for (String profile : Profiles.getProfiles()) { + builder.append("\n"); + if (OneConfigConfig.currentProfile.equals(profile)) builder.append(ChatColor.GREEN); + else builder.append(ChatColor.RED); + builder.append(profile); + } + UChat.chat(builder.toString()); + } + } + + @SubCommand(value = "switch", description = "Switch to a profile", aliases = {"enable", "set", "load"}) + private static class SwitchProfile { + @Main + private static void main(@Name("profile") @Greedy String profile) { + if (!Profiles.doesProfileExist(profile)) { + UChat.chat(ChatColor.RED + "The profile \"" + profile + "\" does not exist!"); + } else { + Profiles.loadProfile(profile); + UChat.chat(ChatColor.GREEN + "Switched to the \"" + profile + "\" profile."); + } + } + } + + @SubCommand(value = "create", description = "Create a new profile", aliases = {"make"}) + private static class Create { + @Main + private static void main(@Name("profile") @Greedy String profile) { + if (Profiles.doesProfileExist(profile)) { + UChat.chat(ChatColor.RED + "The profile \"" + profile + "\" already exists!"); + } else { + Profiles.createProfile(profile); + if (Profiles.doesProfileExist(profile)) Profiles.loadProfile(profile); + UChat.chat(ChatColor.GREEN + "Created the \"" + profile + "\" profile."); + } + } + } + + @SubCommand(value = "rename", description = "Rename a profile") + private static class Rename { + @Main + private static void main(@Name("Old Name") String profile, @Name("New Name") @Greedy String newName) { + if (!Profiles.doesProfileExist(profile)) { + UChat.chat(ChatColor.RED + "The profile \"" + profile + "\" does not exist!"); + } else { + Profiles.renameProfile(profile, newName); + UChat.chat(ChatColor.GREEN + "Renamed the \"" + profile + "\" profile to \" " + newName + "\"."); + } + } + } + + @SubCommand(value = "delete", description = "Delete a profile", aliases = {"remove", "destroy"}) + private static class Delete { + @Main + private static void main(@Name("profile") @Greedy String profile) { + if (!Profiles.doesProfileExist(profile)) { + UChat.chat(ChatColor.RED + "The profile \"" + profile + "\" does not exist!"); + } else { + Profiles.deleteProfile(profile); + UChat.chat(ChatColor.GREEN + "Deleted the \"" + profile + "\" profile."); + } + } + } + } } \ No newline at end of file -- cgit