Skip to content

Commit

Permalink
Fixed Help Command crashing on call.
Browse files Browse the repository at this point in the history
  • Loading branch information
coltonk9043 committed Jul 2, 2023
1 parent 6918542 commit 6a699f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/main/java/net/aoba/cmd/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public void command(String[] commandIn) {
// Runs the command.
command.runCommand(parameterList);
}
} catch(ArrayIndexOutOfBoundsException e) {
sendChatMessage("Invalid Command! Type .aoba help for a list of commands.");
} catch (InvalidSyntaxException e) {
e.PrintToChat();
}
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/net/aoba/cmd/commands/CmdHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package net.aoba.cmd.commands;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import net.aoba.module.Module;
Expand All @@ -36,7 +38,7 @@ public CmdHelp() {
@Override
public void runCommand(String[] parameters) {
if (parameters.length <= 0) {
ShowCommands(0);
ShowCommands(1);
} else if (StringUtils.isNumeric(parameters[0])) {
int page = Integer.parseInt(parameters[0]);
ShowCommands(page);
Expand All @@ -55,14 +57,17 @@ public void runCommand(String[] parameters) {
}

private void ShowCommands(int page) {
CommandManager.sendChatMessage("------------ Help [Page " + page + " of 4] ------------");
CommandManager.sendChatMessage("------------ Help [Page " + page + " of 5] ------------");
CommandManager.sendChatMessage("Use .aoba help [n] to get page n of help.");

// Fetch the commands.
String[] commands = (String[]) Aoba.getInstance().commandManager.getCommands().values().toArray();
for (int i = (page - 1) * indexesPerPage; i <= (page * indexesPerPage + indexesPerPage); i++) {
if (!(i > Aoba.getInstance().commandManager.getNumOfCommands())) {
CommandManager.sendChatMessage(" .aoba " + commands[i]);
// Fetch the commands and dislays their syntax on the screen.
HashMap<String, Command> commands = Aoba.getInstance().commandManager.getCommands();
Set<String> keySet = commands.keySet();
ArrayList<String> listOfCommands = new ArrayList<String>(keySet);

for (int i = (page - 1) * indexesPerPage; i <= (page * indexesPerPage); i++) {
if (i >= 0 && i < Aoba.getInstance().commandManager.getNumOfCommands()) {
CommandManager.sendChatMessage(" .aoba " + listOfCommands.get(i));
}
}
}
Expand Down

0 comments on commit 6a699f3

Please sign in to comment.