Skip to content

Commit a39b437

Browse files
committed
better handle issues of no permission
1 parent 9371f9b commit a39b437

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

common/src/main/java/revxrsal/commands/node/DefaultFailureHandler.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import revxrsal.commands.Lamp;
66
import revxrsal.commands.command.CommandActor;
77
import revxrsal.commands.command.Potential;
8+
import revxrsal.commands.exception.NoPermissionException;
89
import revxrsal.commands.stream.StringStream;
910

1011
import java.util.List;
1112

13+
import static revxrsal.commands.util.Collections.any;
14+
1215
/**
1316
* The default failure handler. This can be overridden in {@link DispatcherSettings}
1417
* from {@link Lamp.Builder#dispatcherSettings()}.
@@ -29,10 +32,17 @@ public static <A extends CommandActor> FailureHandler<A> defaultFailureHandler()
2932

3033
@Override
3134
public void handleFailedAttempts(@NotNull A actor, @NotNull @Unmodifiable List<Potential<A>> failedAttempts, @NotNull StringStream input) {
35+
if (failedAttempts.isEmpty()) {
36+
return;
37+
}
3238
if (failedAttempts.size() == 1) {
3339
failedAttempts.get(0).handleException();
3440
return;
3541
}
42+
if (failedAttempts.get(0).error() instanceof NoPermissionException) {
43+
failedAttempts.get(0).handleException();
44+
return;
45+
}
3646
actor.error("Failed to find a suitable command for your input (\"" + input.source() + "\"). Did you mean:");
3747
for (int i = 0; i < failedAttempts.size(); i++) {
3848
if (i >= MAX_NUMBER_OF_SUGGESTIONS)
@@ -41,4 +51,4 @@ public void handleFailedAttempts(@NotNull A actor, @NotNull @Unmodifiable List<P
4151
actor.reply("- " + failedAttempt.context().command().path());
4252
}
4353
}
44-
}
54+
}

0 commit comments

Comments
 (0)