--- /dev/null
+package de.ddnss.eternal.utils;
+
+import de.ddnss.eternal.utils.io.input.user.CMDCommands;
+
+public class Test {
+ public static void main(String[] cmdargs) {
+
+ System.out.println("Enter command:");
+
+ while (true) {
+ // System.out.print("> ");
+ // String line = scanner.nextLine().trim();
+
+ // // Skip empty input
+ // if (line.isEmpty())
+ // continue;
+
+ // // Split into tokens (command + args)
+ // String[] parts = line.split("\\s+");
+ CMDCommands.scan();
+ }
+ }
+
+ // private static void handleSay(String[] args) {
+ // if (args.length == 0) {
+ // System.out.println("Usage: say <message>");
+ // return;
+ // }
+ // System.out.println(String.join(" ", args));
+ // }
+
+ // private static void handleAdd(String[] args) {
+ // if (args.length != 2) {
+ // System.out.println("Usage: add <num1> <num2>");
+ // return;
+ // }
+
+ // try {
+ // int a = Integer.parseInt(args[0]);
+ // int b = Integer.parseInt(args[1]);
+ // System.out.println("Result: " + (a + b));
+ // } catch (NumberFormatException e) {
+ // System.out.println("Arguments must be numbers.");
+ // }
+ // }
+}
SAY((CommandOption<String> args) -> {
System.out.println(args.get("SAY"));
return null;
- }, new CommandOption<String>() {
});
public final CommandInterface command;
@Override
public void exec() {
this.command.run();
+ }
+
+ @Override
+ public void exec(CommandOption<? extends Object> args) {
+ this.command.run();
};
}
\ No newline at end of file
public interface CommandInterface {
public void exec();
+
+ public void exec(CommandOption<? extends Object> args);
}
import java.util.HashMap;
public class CommandOption<E> extends HashMap<String, E> {
+ public CommandOption(String string, E e) {
+ super();
+ this.put(string, e);
+ }
+
+ public CommandOption() {
+ super();
+ }
}
\ No newline at end of file
import java.util.function.Function;
-public final class ParameterizedCommand<E> implements CommandInterface {
+public final class ParameterizedCommand<E extends Object> implements CommandInterface {
final Function<CommandOption<E>, Void> command;
CommandOption<E> arguments;
this.command.apply(arguments);
};
- public void exec(CommandOption<E> arguments) {
+ @Override
+ public void exec(CommandOption<? extends Object> arguments) {
this.command.apply(arguments);
- };
+ }
+
+ // @Override
+ // public void exec(Object args) {
+ // this.command.apply(args);
+ // };
}
\ No newline at end of file
import java.util.Scanner;
import de.ddnss.eternal.utils.io.input.AvailableCommands;
+import de.ddnss.eternal.utils.io.input.CommandOption;
public class CMDCommands {
- public static void split() {
+ public static void scan() {
+ AvailableCommands command;
+
Scanner scanner = UserInput.scanner();
System.out.println("Enter command:");
// Split into tokens (command + args)
String[] parts = line.split("\\s+");
- AvailableCommands command = AvailableCommands.valueOf(parts[0].toUpperCase()); // first word
- command.command.exec();
+ try {
+ command = AvailableCommands.valueOf(parts[0].toUpperCase()); // first word
+ } catch (IllegalArgumentException e) {
+ System.out.println("Unknown command: " + parts[0]);
+ break;
+ }
+ command.command.exec(new CommandOption<String>("SAY", parts[0]));
}
}
}