Skip to content

Commit 8666573

Browse files
committed
Prevent unauthorized commands from being suggested in tab lists
1 parent 3490b30 commit 8666573

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

common/src/main/java/revxrsal/commands/core/BaseAutoCompleter.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public SuggestionProvider getProvider(CommandParameter parameter) {
9595
@Override public List<String> complete(@NotNull CommandActor actor, @NotNull ArgumentStack arguments) {
9696
CommandPath path = CommandPath.get(arguments.subList(0, arguments.size() - 1));
9797
int originalSize = arguments.size();
98-
ExecutableCommand command = searchForCommand(path);
98+
ExecutableCommand command = searchForCommand(path, actor);
9999
if (command != null) {
100100
command.getPath().forEach(c -> arguments.removeFirst());
101101
return getCompletions(actor, arguments, command);
@@ -112,14 +112,14 @@ public SuggestionProvider getProvider(CommandParameter parameter) {
112112
return complete(actor, ArgumentStack.fromString(buffer));
113113
}
114114

115-
private ExecutableCommand searchForCommand(CommandPath path) {
115+
private ExecutableCommand searchForCommand(CommandPath path, CommandActor actor) {
116116
ExecutableCommand found = handler.getCommand(path);
117-
if (found != null && !found.isSecret()) return found;
117+
if (found != null && !found.isSecret() && found.getPermission().canExecute(actor)) return found;
118118
MutableCommandPath mpath = MutableCommandPath.empty();
119119
for (String p : path) {
120120
mpath.add(p);
121121
found = handler.getCommand(mpath);
122-
if (found != null && !found.isSecret())
122+
if (found != null && !found.isSecret() && found.getPermission().canExecute(actor))
123123
return found;
124124
}
125125
return null;
@@ -190,7 +190,7 @@ private List<String> getCompletions(CommandActor actor, @Unmodifiable ArgumentSt
190190
}
191191
if (originalSize - category.getPath().size() == 1) {
192192
category.getCommands().values().forEach(c -> {
193-
if (!c.isSecret()) suggestions.add(c.getName());
193+
if (!c.isSecret() && c.getPermission().canExecute(actor)) suggestions.add(c.getName());
194194
});
195195
category.getCategories().values().forEach(c -> suggestions.add(c.getName()));
196196
}

0 commit comments

Comments
 (0)