|
16 | 16 | import java.lang.reflect.Method; |
17 | 17 | import java.util.ArrayList; |
18 | 18 | import java.util.Arrays; |
19 | | -import java.util.LinkedList; |
20 | 19 | import java.util.List; |
21 | 20 |
|
22 | 21 | @AllArgsConstructor |
@@ -76,15 +75,21 @@ public Command(Object object, String name, String[] aliases, Method method, Stri |
76 | 75 | public final Command getSubCommand(String[] args) { |
77 | 76 | for (Command command : subCommands) { |
78 | 77 | String[] commandArg = command.getName().split(" "); |
| 78 | + String[] original = commandArg; |
79 | 79 |
|
80 | 80 | List<String> strings = new ArrayList<>(Arrays.asList(commandArg)); |
| 81 | + |
| 82 | + System.out.println("[0] - " + strings); |
| 83 | + |
81 | 84 | List<String> argsList = new ArrayList<>(Arrays.asList(args)); |
82 | 85 |
|
83 | 86 | strings.removeIf(s -> !argsList.contains(s)); |
84 | | - |
85 | 87 | commandArg = strings.toArray(new String[0]); |
86 | 88 |
|
87 | | - if (commandArg.length != 0 && commandArg[commandArg.length - 1].equalsIgnoreCase(args[args.length - 1])) { |
| 89 | + System.out.println("[1] - " + strings); |
| 90 | + System.out.println("[2] - " + Arrays.toString(args)); |
| 91 | + |
| 92 | + if ((original.length - 1) == commandArg.length && commandArg.length != 0 && commandArg[commandArg.length - 1].equalsIgnoreCase(args[commandArg.length - 1])) { |
88 | 93 | return command; |
89 | 94 | } |
90 | 95 | } |
@@ -163,7 +168,17 @@ public void execute(CommandSender commandSender, String[] args, boolean skip) { |
163 | 168 |
|
164 | 169 | for (CommandParameter commandParameter : commandParameters) { |
165 | 170 | try { |
166 | | - objects.add(commandParameter.getCommandProvider().provide(args[commandParameters.indexOf(commandParameter)])); |
| 171 | + if (this.subCommand && subCommand != null && !skip) { |
| 172 | + String[] subArgs = subCommand.getName().split(" "); |
| 173 | + objects.add(commandParameter.getCommandProvider().provide(args[commandParameters.indexOf(commandParameter) + (subArgs.length - 1)])); |
| 174 | + } else { |
| 175 | + objects.add(commandParameter.getCommandProvider().provide(args[commandParameters.indexOf(commandParameter)])); |
| 176 | + } |
| 177 | + } catch (ArrayIndexOutOfBoundsException exception) { |
| 178 | + if (subCommand != null && !skip) { |
| 179 | + commandSender.sendMessage(ChatColor.RED + "Usage: " + subCommand.getUsage()); |
| 180 | + return; |
| 181 | + } |
167 | 182 | } catch (CommandProviderNullException e) { |
168 | 183 | if (!commandParameter.isOptional()) { |
169 | 184 | if (e.getMessage() == null) { |
|
0 commit comments