use of gg.projecteden.nexus.framework.commands.models.events.CommandTabEvent in project Nexus by ProjectEdenGG.
the class CommandListener method onAsyncTabComplete.
@EventHandler
@SneakyThrows
public void onAsyncTabComplete(AsyncTabCompleteEvent event) {
String buffer = event.getBuffer();
if ((!event.isCommand() && !buffer.startsWith("/")) || buffer.indexOf(' ') == -1)
return;
List<String> args = new ArrayList<>(Arrays.asList(buffer.split(" ")));
String alias = trimFirst(args.get(0));
CustomCommand customCommand = Commands.get(alias);
if (customCommand == null)
return;
boolean lastIndexIsEmpty = Strings.isNullOrEmpty(args.get(args.size() - 1));
args.removeIf(Strings::isNullOrEmpty);
if (lastIndexIsEmpty || buffer.endsWith(" "))
args.add("");
args.remove(0);
CommandTabEvent tabEvent = new CommandTabEvent(event.getSender(), customCommand, alias, args, Collections.unmodifiableList(args));
if (!tabEvent.callEvent())
return;
List<String> completions = customCommand.tabComplete(tabEvent);
if (completions == null)
return;
event.setCompletions(completions.stream().distinct().collect(Collectors.toList()));
event.setHandled(true);
}
Aggregations