package net.william278.huskhomes.command; import net.william278.huskhomes.user.CommandUser; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; public interface TabProvider { @Nullable List suggest(@NotNull CommandUser user, @NotNull String[] args); @NotNull default List getSuggestions(@NotNull CommandUser user, @NotNull String[] args) { List suggestions = suggest(user, args); if (suggestions == null) { suggestions = List.of(); } return filter(suggestions, args); } @NotNull default List filter(@NotNull List suggestions, @NotNull String[] args) { return suggestions.stream() .filter(suggestion -> args.length == 0 || suggestion.toLowerCase() .startsWith(args[args.length - 1].toLowerCase().trim())) .toList(); } }