Step 1:
class 1- the interface
Code:
public interface Command {
public void handleCommand(Client c., String command);
}
Step 2:
Command manager
Code:
private Map<String, Command> commands = new HashMap<String, Command>();
public static void loadAllCommands() {
commands.put("commandname", commandObject());
System.out.println(commands.size() + " commands loaded.");
}
public static void handleCommand(Client c, String name) {
if(!commands.contains(name)) {
//command doesnt exit
} else {
commands.get(name).handleCommand(c, name);
}
}
Test command
Code:
public class TestCommand implements Command {
public void handleCommand(Client c, String command) {
}
}