Skip to content

Commit

Permalink
Merge pull request #19 from OsakiTsukiko/master
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonk9043 committed Jul 3, 2023
2 parents 598f9a2 + 77051d7 commit 7e7ba9f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/main/java/net/aoba/cmd/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Command> commands = new HashMap<String, Command>();
Expand Down Expand Up @@ -118,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];
Expand All @@ -132,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();
}
Expand All @@ -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));
}
}
4 changes: 3 additions & 1 deletion src/main/java/net/aoba/cmd/InvalidSyntaxException.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
package net.aoba.cmd;

import net.minecraft.util.Formatting;

public class InvalidSyntaxException extends CommandException {
private static final long serialVersionUID = 1L;

Expand All @@ -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);
}
}
19 changes: 13 additions & 6 deletions src/main/java/net/aoba/cmd/commands/CmdHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, Command> commands = Aoba.getInstance().commandManager.getCommands();
Expand All @@ -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
Expand Down

0 comments on commit 7e7ba9f

Please sign in to comment.