Fix ShutdownCommand message styling (#1427)
* Fix ShutdownCommand message * Fix checkstyle violation.
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package com.velocitypowered.proxy.command.builtin;
|
package com.velocitypowered.proxy.command.builtin;
|
||||||
|
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
import com.mojang.brigadier.Command;
|
import com.mojang.brigadier.Command;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
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.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||||
import com.velocitypowered.proxy.VelocityServer;
|
import com.velocitypowered.proxy.VelocityServer;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
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.
|
* Shuts down the proxy.
|
||||||
@@ -53,11 +55,22 @@ public final class ShutdownCommand {
|
|||||||
StringArgumentType.greedyString())
|
StringArgumentType.greedyString())
|
||||||
.executes(context -> {
|
.executes(context -> {
|
||||||
String reason = context.getArgument("reason", String.class);
|
String reason = context.getArgument("reason", String.class);
|
||||||
server.shutdown(true, MiniMessage.miniMessage().deserialize(
|
Component reasonComponent = null;
|
||||||
MiniMessage.miniMessage().serialize(
|
|
||||||
LegacyComponentSerializer.legacy('&').deserialize(reason)
|
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;
|
return Command.SINGLE_SUCCESS;
|
||||||
})
|
})
|
||||||
).build());
|
).build());
|
||||||
|
Reference in New Issue
Block a user