From be678840de9c927c9e17bcea06ed7aedcea77d1e Mon Sep 17 00:00:00 2001 From: Adrian <68704415+4drian3d@users.noreply.github.com> Date: Sun, 21 Apr 2024 13:49:44 -0500 Subject: [PATCH] Added support for components when using CommandSyntaxException (#1295) --- .../proxy/command/VelocityCommandManager.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java index 80fef3d4..b92c4f50 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/VelocityCommandManager.java @@ -21,6 +21,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.Message; import com.mojang.brigadier.ParseResults; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.suggestion.Suggestion; @@ -33,6 +34,7 @@ import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.command.CommandMeta; import com.velocitypowered.api.command.CommandResult; import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.VelocityBrigadierMessage; import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.command.PostCommandInvocationEvent; import com.velocitypowered.proxy.command.registrar.BrigadierCommandRegistrar; @@ -57,7 +59,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.jetbrains.annotations.VisibleForTesting; /** - * Impelements Velocity's command handler. + * Implements Velocity's command handler. */ public class VelocityCommandManager implements CommandManager { @@ -232,7 +234,12 @@ public class VelocityCommandManager implements CommandManager { boolean isSyntaxError = !e.getType().equals( CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand()); if (isSyntaxError) { - source.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED)); + final Message message = e.getRawMessage(); + if (message instanceof VelocityBrigadierMessage velocityMessage) { + source.sendMessage(velocityMessage.asComponent().applyFallbackStyle(NamedTextColor.RED)); + } else { + source.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED)); + } result = com.velocitypowered.api.command.CommandResult.SYNTAX_ERROR; // This is, of course, a lie, but the API will need to change... return true;