From 5e20ec19ff05258d64fe0662d01e18ec20df5b9f Mon Sep 17 00:00:00 2001 From: Alex <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Fri, 23 May 2025 15:23:38 +0200 Subject: [PATCH] Stabilize and expose suggestions API (#1406) * Expose suggestions API * Improve javadoc of suggestions api --- .../api/command/CommandManager.java | 23 +++++++++++++++++++ .../proxy/command/VelocityCommandManager.java | 17 ++------------ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/command/CommandManager.java b/api/src/main/java/com/velocitypowered/api/command/CommandManager.java index ad389373..c36ca927 100644 --- a/api/src/main/java/com/velocitypowered/api/command/CommandManager.java +++ b/api/src/main/java/com/velocitypowered/api/command/CommandManager.java @@ -7,8 +7,10 @@ package com.velocitypowered.api.command; +import com.mojang.brigadier.suggestion.Suggestions; import com.velocitypowered.api.event.command.CommandExecuteEvent; import java.util.Collection; +import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; import org.checkerframework.checker.nullness.qual.Nullable; @@ -116,6 +118,27 @@ public interface CommandManager { */ CompletableFuture executeImmediatelyAsync(CommandSource source, String cmdLine); + /** + * Asynchronously collects suggestions to fill in the given command {@code cmdLine}. + * Returns only the raw completion suggestions without tooltips. + * + * @param source the source to execute the command for + * @param cmdLine the partially completed command + * @return a {@link CompletableFuture} eventually completed with a {@link List}, possibly empty + */ + CompletableFuture> offerSuggestions(CommandSource source, String cmdLine); + + /** + * Asynchronously collects suggestions to fill in the given command {@code cmdLine}. + * Returns the brigadier {@link Suggestions} with tooltips for each result. + * + * @param source the source to execute the command for + * @param cmdLine the partially completed command + * @return a {@link CompletableFuture} eventually completed with {@link Suggestions}, possibly + * empty + */ + CompletableFuture offerBrigadierSuggestions(CommandSource source, String cmdLine); + /** * Returns an immutable collection of the case-insensitive aliases registered * on this manager. diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java index b4b0e850..21f82f34 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -300,27 +300,14 @@ public class VelocityCommandManager implements CommandManager { ); } - /** - * Returns suggestions to fill in the given command. - * - * @param source the source to execute the command for - * @param cmdLine the partially completed command - * @return a {@link CompletableFuture} eventually completed with a {@link List}, possibly empty - */ + @Override public CompletableFuture> offerSuggestions(final CommandSource source, final String cmdLine) { return offerBrigadierSuggestions(source, cmdLine) .thenApply(suggestions -> Lists.transform(suggestions.getList(), Suggestion::getText)); } - /** - * Returns suggestions to fill in the given command. - * - * @param source the source to execute the command for - * @param cmdLine the partially completed command - * @return a {@link CompletableFuture} eventually completed with {@link Suggestions}, possibly - * empty - */ + @Override public CompletableFuture offerBrigadierSuggestions( final CommandSource source, final String cmdLine) { Preconditions.checkNotNull(source, "source");