|
5 | 5 | import revxrsal.commands.Lamp; |
6 | 6 | import revxrsal.commands.command.CommandActor; |
7 | 7 | import revxrsal.commands.command.Potential; |
| 8 | +import revxrsal.commands.exception.ExpectedLiteralException; |
8 | 9 | import revxrsal.commands.exception.NoPermissionException; |
9 | 10 | import revxrsal.commands.stream.StringStream; |
10 | 11 |
|
11 | 12 | import java.util.List; |
12 | 13 |
|
13 | 14 | import static revxrsal.commands.util.Collections.any; |
| 15 | +import static revxrsal.commands.util.Collections.filter; |
14 | 16 |
|
15 | 17 | /** |
16 | 18 | * The default failure handler. This can be overridden in {@link DispatcherSettings} |
@@ -39,16 +41,18 @@ public void handleFailedAttempts(@NotNull A actor, @NotNull @Unmodifiable List<P |
39 | 41 | failedAttempts.get(0).handleException(); |
40 | 42 | return; |
41 | 43 | } |
42 | | - if (failedAttempts.get(0).error() instanceof NoPermissionException) { |
43 | | - failedAttempts.get(0).handleException(); |
44 | | - return; |
45 | | - } |
46 | | - actor.error("Failed to find a suitable command for your input (\"" + input.source() + "\"). Did you mean:"); |
47 | | - for (int i = 0; i < failedAttempts.size(); i++) { |
48 | | - if (i >= MAX_NUMBER_OF_SUGGESTIONS) |
49 | | - break; |
50 | | - Potential<A> failedAttempt = failedAttempts.get(i); |
51 | | - actor.reply("- " + failedAttempt.context().command().path()); |
| 44 | + |
| 45 | + List<Potential<A>> realExceptions = filter(failedAttempts, v -> !(v.error() instanceof ExpectedLiteralException)); |
| 46 | + if (realExceptions.isEmpty()) { |
| 47 | + actor.error("Failed to find a suitable command for your input (\"" + input.source() + "\"). Did you mean:"); |
| 48 | + for (int i = 0; i < failedAttempts.size(); i++) { |
| 49 | + if (i >= MAX_NUMBER_OF_SUGGESTIONS) |
| 50 | + break; |
| 51 | + Potential<A> failedAttempt = failedAttempts.get(i); |
| 52 | + actor.reply("- " + failedAttempt.context().command().path()); |
| 53 | + } |
| 54 | + } else { |
| 55 | + realExceptions.get(0).handleException(); |
52 | 56 | } |
53 | 57 | } |
54 | 58 | } |
0 commit comments