|
30 | 30 | import java.util.Objects; |
31 | 31 | import java.util.function.Consumer; |
32 | 32 | import java.util.function.Function; |
| 33 | +import java.util.stream.Collectors; |
33 | 34 | import net.kyori.adventure.audience.Audience; |
34 | 35 | import net.kyori.adventure.text.Component; |
35 | 36 | import net.kyori.adventure.text.ComponentLike; |
| 37 | +import net.kyori.adventure.text.JoinConfiguration; |
36 | 38 | import net.kyori.adventure.text.event.ClickEvent; |
37 | 39 | import net.kyori.adventure.text.event.HoverEvent; |
38 | 40 | import net.kyori.adventure.text.format.NamedTextColor; |
@@ -99,14 +101,26 @@ public static <C> MessageFactory<C, InvalidSyntaxException> createDefaultInvalid |
99 | 101 | */ |
100 | 102 | @API(status = API.Status.STABLE, since = "2.0.0") |
101 | 103 | public static <C> MessageFactory<C, InvalidCommandSenderException> createDefaultInvalidSenderHandler() { |
102 | | - return (formatter, ctx) -> text() |
103 | | - .color(NamedTextColor.RED) |
104 | | - .append(ctx.context().formatCaption( |
105 | | - formatter, |
106 | | - StandardCaptionKeys.EXCEPTION_INVALID_SENDER, |
107 | | - RichVariable.of("actual", text(TypeUtils.simpleName(ctx.context().sender().getClass()), NamedTextColor.GRAY)), |
108 | | - RichVariable.of("expected", text(TypeUtils.simpleName(ctx.exception().requiredSender()), NamedTextColor.GRAY)) |
109 | | - )); |
| 104 | + return (formatter, ctx) -> { |
| 105 | + final boolean multiple = ctx.exception().requiredSenderTypes().size() > 1; |
| 106 | + final Component expected = multiple |
| 107 | + ? Component.join( |
| 108 | + JoinConfiguration.commas(true), |
| 109 | + ctx.exception().requiredSenderTypes().stream() |
| 110 | + .map(TypeUtils::simpleName) |
| 111 | + .map(name -> text(name, NamedTextColor.GRAY)) |
| 112 | + .collect(Collectors.toList()) |
| 113 | + ) |
| 114 | + : text(TypeUtils.simpleName(ctx.exception().requiredSenderTypes().iterator().next()), NamedTextColor.GRAY); |
| 115 | + return text() |
| 116 | + .color(NamedTextColor.RED) |
| 117 | + .append(ctx.context().formatCaption( |
| 118 | + formatter, |
| 119 | + multiple ? StandardCaptionKeys.EXCEPTION_INVALID_SENDER_LIST : StandardCaptionKeys.EXCEPTION_INVALID_SENDER, |
| 120 | + RichVariable.of("actual", text(TypeUtils.simpleName(ctx.context().sender().getClass()), NamedTextColor.GRAY)), |
| 121 | + RichVariable.of("expected", expected) |
| 122 | + )); |
| 123 | + }; |
110 | 124 | } |
111 | 125 |
|
112 | 126 | /** |
|
0 commit comments