package fr.pandacube.lib.commands; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.context.CommandContextBuilder; import com.mojang.brigadier.context.StringRange; import com.mojang.brigadier.context.SuggestionContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.Suggestion; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import com.mojang.brigadier.tree.CommandNode; import fr.pandacube.lib.reflect.Reflect; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.concurrent.CompletableFuture; /** * Utility methods to replace some functionalities of Brigadier, especialy suggestion sorting that we don’t like. */ public class BrigadierSuggestionsUtil { /** * Gets suggestions with the provided parsed command. *
* This is a reimplementation of {@link CommandDispatcher#getCompletionSuggestions(ParseResults, int)} that
* keeps the original ordering of the suggestions.
* @param parsed the parsed command.
* @return the suggestions.
* @param
* This is a reimplementation of {@link Suggestions#merge(String, Collection)} that keeps the original ordering of
* the suggestions.
* @param input the command on which are based the suggestions.
* @param suggestions the {@link Suggestions} to merge.
* @return a {@link Suggestions}.
* @see Suggestions#create(String, Collection)
*/
public static Suggestions mergeSuggestionsOriginalOrdering(String input, Collection
* This is a reimplementation of {@link Suggestions#create(String, Collection)} that keeps the original ordering of
* the suggestions.
* @param command the command on which are based the suggestions.
* @param suggestions the Collection of {@link Suggestion}.
* @return a {@link Suggestions}.
* @see Suggestions#create(String, Collection)
*/
public static Suggestions createSuggestionsOriginalOrdering(String command, Collection the sender type.
* @see CommandDispatcher#getCompletionSuggestions(ParseResults, int)
*/
public static CompletableFuture parsed) {
int cursor = parsed.getReader().getTotalLength();
final CommandContextBuilder context = parsed.getContext();
final SuggestionContext nodeBeforeCursor = context.findSuggestionContext(cursor);
final CommandNode parent = nodeBeforeCursor.parent;
final int start = Math.min(nodeBeforeCursor.startPos, cursor);
final String fullInput = parsed.getReader().getString();
final String truncatedInput = fullInput.substring(0, cursor);
@SuppressWarnings("unchecked") final CompletableFuture node : parent.getChildren()) {
CompletableFuture