From bff92c8d193ee4afc14cedc39a0a031da9e1c87c Mon Sep 17 00:00:00 2001 From: OsakiTsukiko Date: Mon, 3 Jul 2023 14:37:31 +0300 Subject: [PATCH 1/2] fix command formatting + make em fancy --- .../java/net/aoba/cmd/CommandManager.java | 4 +++- .../net/aoba/cmd/InvalidSyntaxException.java | 4 +++- .../java/net/aoba/cmd/commands/CmdHelp.java | 19 +++++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/aoba/cmd/CommandManager.java b/src/main/java/net/aoba/cmd/CommandManager.java index f81a28a..5714f62 100644 --- a/src/main/java/net/aoba/cmd/CommandManager.java +++ b/src/main/java/net/aoba/cmd/CommandManager.java @@ -22,12 +22,14 @@ package net.aoba.cmd; import java.lang.reflect.Field; +import java.text.Format; import java.util.HashMap; import net.aoba.Aoba; import net.aoba.cmd.commands.*; import net.minecraft.client.MinecraftClient; import net.minecraft.text.Text; +import net.minecraft.util.Formatting; public class CommandManager { private HashMap commands = new HashMap(); @@ -144,6 +146,6 @@ public void command(String[] commandIn) { */ public static void sendChatMessage(String message) { MinecraftClient mc = MinecraftClient.getInstance(); - mc.inGameHud.getChatHud().addMessage(Text.of("§5[Aoba]§f " + message)); + mc.inGameHud.getChatHud().addMessage(Text.of(Formatting.DARK_PURPLE + "[" + Formatting.LIGHT_PURPLE + "Aoba" + Formatting.DARK_PURPLE + "] " + Formatting.RESET + message)); } } diff --git a/src/main/java/net/aoba/cmd/InvalidSyntaxException.java b/src/main/java/net/aoba/cmd/InvalidSyntaxException.java index 2f1e3fd..9b8849c 100644 --- a/src/main/java/net/aoba/cmd/InvalidSyntaxException.java +++ b/src/main/java/net/aoba/cmd/InvalidSyntaxException.java @@ -21,6 +21,8 @@ */ package net.aoba.cmd; +import net.minecraft.util.Formatting; + public class InvalidSyntaxException extends CommandException { private static final long serialVersionUID = 1L; @@ -30,6 +32,6 @@ public InvalidSyntaxException(Command cmd) { @Override public void PrintToChat() { - CommandManager.sendChatMessage("Invalid Usage! Usage: .aoba " + cmd.getName() + " " + cmd.getSyntax()); + CommandManager.sendChatMessage("Invalid Usage! Usage: " + Formatting.LIGHT_PURPLE + ".aoba " + cmd.getName() + " " + cmd.getSyntax() + Formatting.RESET); } } diff --git a/src/main/java/net/aoba/cmd/commands/CmdHelp.java b/src/main/java/net/aoba/cmd/commands/CmdHelp.java index 9531116..1588d2e 100644 --- a/src/main/java/net/aoba/cmd/commands/CmdHelp.java +++ b/src/main/java/net/aoba/cmd/commands/CmdHelp.java @@ -21,6 +21,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Set; + +import net.minecraft.util.Formatting; import org.apache.commons.lang3.StringUtils; import net.aoba.module.Module; import net.aoba.Aoba; @@ -47,18 +49,22 @@ public void runCommand(String[] parameters) { if (module == null) { CommandManager.sendChatMessage("Could not find Module '" + parameters[0] + "'."); } else { - CommandManager.sendChatMessage("------------ " + module.getName() + "Help ------------"); - CommandManager.sendChatMessage("Name: " + module.getName()); - CommandManager.sendChatMessage("Description: " + module.getDescription()); - CommandManager.sendChatMessage("Keybind: " + module.getBind().getTranslationKey()); + String title = "------------ " + Formatting.LIGHT_PURPLE + module.getName() + " Help" + Formatting.RESET + " ------------"; + String unformatted_title = "------------ " + module.getName() + " Help ------------"; + CommandManager.sendChatMessage(title); + CommandManager.sendChatMessage("Name: " + Formatting.LIGHT_PURPLE + module.getName() + Formatting.RESET); + CommandManager.sendChatMessage("Description: " + Formatting.LIGHT_PURPLE + module.getDescription() + Formatting.RESET); + CommandManager.sendChatMessage("Keybind: " + Formatting.LIGHT_PURPLE + module.getBind().getTranslationKey() + Formatting.RESET); + CommandManager.sendChatMessage("-".repeat(unformatted_title.length() - 2)); // mc font characters are not the same width but eh.. } } } private void ShowCommands(int page) { - CommandManager.sendChatMessage("------------ Help [Page " + page + " of 5] ------------"); - CommandManager.sendChatMessage("Use .aoba help [n] to get page n of help."); + String title = "------------ Help [Page " + page + " of 5] ------------"; // TODO: remove hardcoded page length + CommandManager.sendChatMessage(title); + CommandManager.sendChatMessage("Use " + Formatting.LIGHT_PURPLE + ".aoba help [n]" + Formatting.RESET + " to get page n of help."); // Fetch the commands and dislays their syntax on the screen. HashMap commands = Aoba.getInstance().commandManager.getCommands(); @@ -70,6 +76,7 @@ private void ShowCommands(int page) { CommandManager.sendChatMessage(" .aoba " + listOfCommands.get(i)); } } + CommandManager.sendChatMessage("-".repeat(title.length() - 2)); // mc font characters are not the same width but eh.. } @Override From 77051d73bbef67a3f866777d8ec0ded48d7279be Mon Sep 17 00:00:00 2001 From: OsakiTsukiko Date: Mon, 3 Jul 2023 14:43:23 +0300 Subject: [PATCH 2/2] small formatting fix --- src/main/java/net/aoba/cmd/CommandManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/aoba/cmd/CommandManager.java b/src/main/java/net/aoba/cmd/CommandManager.java index 5714f62..7bf3f6d 100644 --- a/src/main/java/net/aoba/cmd/CommandManager.java +++ b/src/main/java/net/aoba/cmd/CommandManager.java @@ -120,7 +120,7 @@ public void command(String[] commandIn) { // If the command does not exist, throw an error. if (command == null) - sendChatMessage("Invalid Command! Type .aoba help for a list of commands."); + sendChatMessage("Invalid Command! Type " + Formatting.LIGHT_PURPLE + ".aoba help" + Formatting.RESET + " for a list of commands."); else { // Otherwise, create a new parameter list. String[] parameterList = new String[commandIn.length - 2]; @@ -134,7 +134,7 @@ public void command(String[] commandIn) { command.runCommand(parameterList); } } catch(ArrayIndexOutOfBoundsException e) { - sendChatMessage("Invalid Command! Type .aoba help for a list of commands."); + sendChatMessage("Invalid Command! Type " + Formatting.LIGHT_PURPLE + ".aoba help" + Formatting.RESET + " for a list of commands."); } catch (InvalidSyntaxException e) { e.PrintToChat(); }