From 876b9c36012d6ed91ca7b7c0a747f6c2809ba1b3 Mon Sep 17 00:00:00 2001 From: Isaac - The456 Date: Mon, 27 Jan 2025 04:03:37 +0000 Subject: [PATCH] Fix ShutdownCommand message styling (#1427) * Fix ShutdownCommand message * Fix checkstyle violation. --- .../command/builtin/ShutdownCommand.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ShutdownCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ShutdownCommand.java index 402a0ce8..b60ead91 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ShutdownCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/ShutdownCommand.java @@ -17,6 +17,7 @@ package com.velocitypowered.proxy.command.builtin; +import com.google.gson.JsonSyntaxException; import com.mojang.brigadier.Command; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; @@ -25,8 +26,9 @@ import com.velocitypowered.api.command.BrigadierCommand; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.proxy.ConsoleCommandSource; import com.velocitypowered.proxy.VelocityServer; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; /** * Shuts down the proxy. @@ -53,11 +55,22 @@ public final class ShutdownCommand { StringArgumentType.greedyString()) .executes(context -> { String reason = context.getArgument("reason", String.class); - server.shutdown(true, MiniMessage.miniMessage().deserialize( - MiniMessage.miniMessage().serialize( - LegacyComponentSerializer.legacy('&').deserialize(reason) - ) - )); + Component reasonComponent = null; + + if (reason.startsWith("{") || reason.startsWith("[") || reason.startsWith("\"")) { + try { + reasonComponent = GsonComponentSerializer.gson() + .deserializeOrNull(reason); + } catch (JsonSyntaxException expected) { + + } + } + + if (reasonComponent == null) { + reasonComponent = MiniMessage.miniMessage().deserialize(reason); + } + + server.shutdown(true, reasonComponent); return Command.SINGLE_SUCCESS; }) ).build());