Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tab completions forwarding for inaccessible commands #1329

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.velocitypowered.api.event.command.CommandExecuteEvent;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand Down Expand Up @@ -126,4 +127,15 @@ default void register(String alias, Command command, String... otherAliases) {
* @return true if the alias is registered; false otherwise
*/
boolean hasCommand(String alias);

/**
* Returns whether the given alias is registered on this manager
* and can be used by the given {@link CommandSource}.
* See {@link com.mojang.brigadier.builder.ArgumentBuilder#requires(Predicate)}
*
* @param alias the command alias to check
* @param source the command source
* @return true if the alias is registered and usable; false otherwise
*/
boolean hasCommand(String alias, CommandSource source);
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,19 @@ public Collection<String> getAliases() {

@Override
public boolean hasCommand(final String alias) {
return getCommand(alias) != null;
}

@Override
public boolean hasCommand(String alias, CommandSource source) {
Preconditions.checkNotNull(source, "source");
CommandNode<CommandSource> command = getCommand(alias);
return command != null && command.canUse(source);
}

CommandNode<CommandSource> getCommand(final String alias) {
Preconditions.checkNotNull(alias, "alias");
return dispatcher.getRoot().getChild(alias.toLowerCase(Locale.ENGLISH)) != null;
return dispatcher.getRoot().getChild(alias.toLowerCase(Locale.ENGLISH));
}

@VisibleForTesting // this constitutes unsafe publication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ private boolean handleCommandTabComplete(TabCompleteRequestPacket packet) {
}

String commandLabel = command.substring(0, commandEndPosition);
if (!server.getCommandManager().hasCommand(commandLabel)) {
if (!server.getCommandManager().hasCommand(commandLabel, player)) {
if (player.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13)) {
// Outstanding tab completes are recorded for use with 1.12 clients and below to provide
// additional tab completion support.
Expand Down