Skip to content

Commit

Permalink
Implement basic command flag suggestion filter (#1304)
Browse files Browse the repository at this point in the history
Signed-off-by: Pugzy <[email protected]>
  • Loading branch information
Pugzy authored Apr 12, 2024
1 parent ac539d2 commit 639b4b3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions core/src/main/java/tc/oc/pgm/command/util/CommandGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
import cloud.commandframework.exceptions.NoPermissionException;
import cloud.commandframework.exceptions.parsing.ParserException;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import cloud.commandframework.execution.FilteringCommandSuggestionProcessor;
import cloud.commandframework.extra.confirmation.CommandConfirmationManager;
import cloud.commandframework.meta.CommandMeta;
import cloud.commandframework.minecraft.extras.MinecraftHelp;
import cloud.commandframework.paper.PaperCommandManager;
import io.leangen.geantyref.TypeToken;
import java.lang.reflect.Type;
import java.util.Locale;
import java.util.function.Function;
import java.util.function.Supplier;
import net.kyori.adventure.text.Component;
Expand Down Expand Up @@ -85,9 +87,14 @@ protected PaperCommandManager<CommandSender> createCommandManager() throws Excep
context ->
context.getCommandContext().store(CommandKeys.INPUT_QUEUE, context.getInputQueue()));

// By default, suggestions run by a filtered processor.
// By default, it prevents suggestions like "s" -> "Something" or "someh" -> "Something"
manager.commandSuggestionProcessor((cpc, strings) -> strings);
// Basic suggestion filtering processor which avoids suggesting flags when not applicable
manager.commandSuggestionProcessor(
new FilteringCommandSuggestionProcessor<>(
FilteringCommandSuggestionProcessor.Filter.Simple.contextFree(
(s, i) ->
i.isEmpty()
|| !s.startsWith("-")
|| s.toLowerCase(Locale.ROOT).startsWith(i.toLowerCase(Locale.ROOT)))));

return manager;
}
Expand Down

0 comments on commit 639b4b3

Please sign in to comment.