13
0
geforkt von Mirrors/Velocity

Shutdown command improvements (#680)

- Migrate to Brigadier usage
- Added MiniMessage support for custom shutdown reason
Dieser Commit ist enthalten in:
4drian3d 2022-04-08 21:56:41 -05:00 committet von GitHub
Ursprung 44dc2e7ca0
Commit 2a39b24770
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 34 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -209,7 +209,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
// Initialize commands first // Initialize commands first
commandManager.register("velocity", new VelocityCommand(this)); commandManager.register("velocity", new VelocityCommand(this));
commandManager.register("server", new ServerCommand(this)); commandManager.register("server", new ServerCommand(this));
commandManager.register("shutdown", new ShutdownCommand(this),"end"); commandManager.register("shutdown", ShutdownCommand.command(this), "end");
new GlistCommand(this).register(); new GlistCommand(this).register();
this.doStartupConfigLoad(); this.doStartupConfigLoad();

Datei anzeigen

@ -17,30 +17,42 @@
package com.velocitypowered.proxy.command.builtin; package com.velocitypowered.proxy.command.builtin;
import com.velocitypowered.api.command.RawCommand; import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
public class ShutdownCommand implements RawCommand { public final class ShutdownCommand {
private ShutdownCommand(){}
private final VelocityServer server; /**
* Creates a Velocity Shutdown Command.
public ShutdownCommand(VelocityServer server) { * @param server the proxy instance
this.server = server; * @return the Shutdown Command
} */
public static BrigadierCommand command(final VelocityServer server) {
@Override return new BrigadierCommand(LiteralArgumentBuilder.<CommandSource>literal("shutdown")
public void execute(final Invocation invocation) { .requires(source -> source == server.getConsoleCommandSource())
String reason = invocation.arguments(); .executes(context -> {
if (reason.isEmpty() || reason.trim().isEmpty()) { server.shutdown(true);
server.shutdown(true); return Command.SINGLE_SUCCESS;
} else { })
server.shutdown(true, LegacyComponentSerializer.legacy('&').deserialize(reason)); .then(RequiredArgumentBuilder.<CommandSource, String>argument("reason", StringArgumentType.greedyString())
} .executes(context -> {
} String reason = context.getArgument("reason", String.class);
server.shutdown(true, MiniMessage.miniMessage().deserialize(
@Override MiniMessage.miniMessage().serialize(
public boolean hasPermission(final Invocation invocation) { LegacyComponentSerializer.legacy('&').deserialize(reason)
return invocation.source() == server.getConsoleCommandSource(); )
));
return Command.SINGLE_SUCCESS;
})
).build());
} }
} }