48 lines
1.4 KiB
Java
48 lines
1.4 KiB
Java
package me.zinch.commands;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
/**
|
|
* Manages the registration and retrieval of commands.
|
|
*/
|
|
public class CommandManager {
|
|
private static final List<Command> commandList = new ArrayList<>();
|
|
|
|
public static void registerCommand(Command command) {
|
|
commandList.add(command);
|
|
}
|
|
|
|
public static String getRegisteredCommand() {
|
|
return String.join("\n", commandList
|
|
.stream()
|
|
.map(command -> String.format("%s - %s", command.getName(), command.getDescription()))
|
|
.toList());
|
|
}
|
|
|
|
public static Optional<Command> getCommandByInput(String input) {
|
|
return commandList.stream().filter(command -> command.checkPattern(input)).findFirst();
|
|
}
|
|
|
|
static {
|
|
registerCommand(new Show());
|
|
registerCommand(new Exit());
|
|
registerCommand(new Info());
|
|
registerCommand(new Clear());
|
|
registerCommand(new PrintAscending());
|
|
registerCommand(new PrintUniqueManufactureCost());
|
|
registerCommand(new FilterContainsName());
|
|
registerCommand(new Add());
|
|
registerCommand(new Update());
|
|
registerCommand(new Remove());
|
|
registerCommand(new AddIfMax());
|
|
registerCommand(new AddIfMin());
|
|
registerCommand(new RemoveLower());
|
|
registerCommand(new Save());
|
|
registerCommand(new ExecuteScript());
|
|
|
|
registerCommand(new Help());
|
|
}
|
|
}
|