Skip to content

Commit a243e45

Browse files
committed
Some code based improvements
1 parent 78a302c commit a243e45

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

src/main/java/me/despical/commandframework/CommandFramework.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,10 @@ private Map.Entry<Command, Map.Entry<Method, Object>> getAssociatedCommand(@NotN
335335
final String name = cmd.name();
336336

337337
if (name.equalsIgnoreCase(commandName) || Stream.of(cmd.aliases()).anyMatch(commandName::equalsIgnoreCase)) {
338-
command = cmd;
339-
break;
338+
return Utils.mapEntry(cmd, commands.get(cmd));
340339
}
341340
}
342341

343-
// If we found the command return it, otherwise return null
344-
if (command != null) {
345-
return Utils.mapEntry(command, commands.get(command));
346-
}
347-
348342
// Return null if the given command is not registered by Command Framework
349343
return null;
350344
}
@@ -485,34 +479,22 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.comm
485479

486480
@Nullable
487481
private Map.Entry<Completer, Map.Entry<Method, Object>> getAssociatedCompleter(@NotNull String commandName, @NotNull String[] possibleArgs) {
488-
Completer completer = null;
489-
490482
for (Completer comp : subCommandCompletions.keySet()) {
491483
final String name = comp.name(), cmdName = commandName + (possibleArgs.length == 0 ? "" : "." + String.join(".", Arrays.copyOfRange(possibleArgs, 0, name.split("\\.").length - 1)));
492484

493485
if (name.equalsIgnoreCase(cmdName) || Stream.of(comp.aliases()).anyMatch(target -> target.equalsIgnoreCase(cmdName) || target.equalsIgnoreCase(commandName))) {
494-
completer = comp;
495-
break;
486+
return Utils.mapEntry(comp, subCommandCompletions.get(comp));
496487
}
497488
}
498489

499-
if (completer != null) {
500-
return Utils.mapEntry(completer, subCommandCompletions.get(completer));
501-
}
502-
503490
for (Completer comp : commandCompletions.keySet()) {
504491
final String name = comp.name();
505492

506493
if (name.equalsIgnoreCase(commandName) || Stream.of(comp.aliases()).anyMatch(commandName::equalsIgnoreCase)) {
507-
completer = comp;
508-
break;
494+
return Utils.mapEntry(comp, commandCompletions.get(comp));
509495
}
510496
}
511497

512-
if (completer != null) {
513-
return Utils.mapEntry(completer, commandCompletions.get(completer));
514-
}
515-
516498
return null;
517499
}
518500

0 commit comments

Comments
 (0)