From 0933a56a4d0cc33793b6ec7a3968e88ba6ceb926 Mon Sep 17 00:00:00 2001 From: David Hermann Date: Wed, 4 Jan 2023 02:47:11 +0100 Subject: [PATCH] Added the help command This command prints a list of all commands which are available --- .../bitbiome/commands/CommandListener.java | 8 +------ .../org/bitbiome/commands/HelpCommand.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/bitbiome/commands/HelpCommand.java diff --git a/src/main/java/org/bitbiome/commands/CommandListener.java b/src/main/java/org/bitbiome/commands/CommandListener.java index 9ed47ee..f10bdfe 100644 --- a/src/main/java/org/bitbiome/commands/CommandListener.java +++ b/src/main/java/org/bitbiome/commands/CommandListener.java @@ -10,13 +10,7 @@ public class CommandListener { public CommandListener() { commands = new HashMap<>(); - /* - * Commandfield - * - * commands.put("CommandName", new CommandClass()); - * - * - */ + commands.put("help", new HelpCommand()); } public HashMap returnCommands() { diff --git a/src/main/java/org/bitbiome/commands/HelpCommand.java b/src/main/java/org/bitbiome/commands/HelpCommand.java new file mode 100644 index 0000000..45e8137 --- /dev/null +++ b/src/main/java/org/bitbiome/commands/HelpCommand.java @@ -0,0 +1,22 @@ +package org.bitbiome.commands; + +import org.bitbiome.Boot; + +import java.util.HashMap; +import java.util.Scanner; + +public class HelpCommand implements CommandAPI { + + + @Override + public void performCommand(Scanner scanner, boolean isRunning, String message) { + HashMap commands = Boot.instance.getCmdListener().returnCommands(); + StringBuilder outputMessage = new StringBuilder(); + outputMessage.append("Hier ist eine Liste der Commands:\n"); + commands.forEach((key, value) -> { + outputMessage.append("- ").append(key).append("\n"); + }); + System.out.println(outputMessage.toString()); + } + +}