13
0
geforkt von Mirrors/Velocity

Add send command (#1073)

Dieser Commit ist enthalten in:
Angelillo15 2023-10-29 02:14:19 +02:00 committet von GitHub
Ursprung 7f8edf8c77
Commit 81145e45df
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
5 geänderte Dateien mit 130 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -38,6 +38,7 @@ import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.util.ProxyVersion; import com.velocitypowered.api.util.ProxyVersion;
import com.velocitypowered.proxy.command.VelocityCommandManager; import com.velocitypowered.proxy.command.VelocityCommandManager;
import com.velocitypowered.proxy.command.builtin.GlistCommand; import com.velocitypowered.proxy.command.builtin.GlistCommand;
import com.velocitypowered.proxy.command.builtin.SendCommand;
import com.velocitypowered.proxy.command.builtin.ServerCommand; import com.velocitypowered.proxy.command.builtin.ServerCommand;
import com.velocitypowered.proxy.command.builtin.ShutdownCommand; import com.velocitypowered.proxy.command.builtin.ShutdownCommand;
import com.velocitypowered.proxy.command.builtin.VelocityCommand; import com.velocitypowered.proxy.command.builtin.VelocityCommand;
@ -216,6 +217,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
commandManager.register("shutdown", ShutdownCommand.command(this), commandManager.register("shutdown", ShutdownCommand.command(this),
"end", "stop"); "end", "stop");
new GlistCommand(this).register(); new GlistCommand(this).register();
new SendCommand(this).register();
this.doStartupConfigLoad(); this.doStartupConfigLoad();

Datei anzeigen

@ -30,4 +30,6 @@ public class CommandMessages {
"velocity.command.players-only", NamedTextColor.RED); "velocity.command.players-only", NamedTextColor.RED);
public static final TranslatableComponent SERVER_DOES_NOT_EXIST = Component.translatable( public static final TranslatableComponent SERVER_DOES_NOT_EXIST = Component.translatable(
"velocity.command.server-does-not-exist", NamedTextColor.RED); "velocity.command.server-does-not-exist", NamedTextColor.RED);
public static final TranslatableComponent PLAYER_NOT_FOUND = Component.translatable(
"velocity.command.player-not-found", NamedTextColor.RED);
} }

Datei anzeigen

@ -0,0 +1,121 @@
/*
* Copyright (C) 2020-2023 Velocity Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.velocitypowered.proxy.command.builtin;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.tree.ArgumentCommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.permission.Tristate;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import java.util.Objects;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
/**
* Implements the Velocity default {@code /send} command.
*/
public class SendCommand {
private final ProxyServer server;
private static final String SERVER_ARG = "server";
private static final String PLAYER_ARG = "player";
public SendCommand(ProxyServer server) {
this.server = server;
}
/**
* Registers this command.
*/
public void register() {
LiteralCommandNode<CommandSource> totalNode = LiteralArgumentBuilder
.<CommandSource>literal("send")
.requires(source ->
source.getPermissionValue("velocity.command.send") == Tristate.TRUE)
.executes(this::usage)
.build();
ArgumentCommandNode<CommandSource, String> playerNode = RequiredArgumentBuilder
.<CommandSource, String>argument("player", StringArgumentType.word())
.suggests((context, builder) -> {
for (Player player : server.getAllPlayers()) {
builder.suggest(player.getUsername());
}
builder.suggest("all");
return builder.buildFuture();
})
.executes(this::usage)
.build();
ArgumentCommandNode<CommandSource, String> serverNode = RequiredArgumentBuilder
.<CommandSource, String>argument("server", StringArgumentType.word())
.suggests((context, builder) -> {
for (RegisteredServer server : server.getAllServers()) {
builder.suggest(server.getServerInfo().getName());
}
return builder.buildFuture();
})
.executes(this::send)
.build();
totalNode.addChild(playerNode);
playerNode.addChild(serverNode);
server.getCommandManager().register(new BrigadierCommand(totalNode));
}
private int usage(CommandContext<CommandSource> context) {
context.getSource().sendMessage(
Component.translatable("velocity.command.send-usage", NamedTextColor.YELLOW)
);
return 1;
}
private int send(CommandContext<CommandSource> context) {
String serverName = context.getArgument(SERVER_ARG, String.class);
String player = context.getArgument(PLAYER_ARG, String.class);
if (server.getServer(serverName).isEmpty()) {
context.getSource().sendMessage(
CommandMessages.SERVER_DOES_NOT_EXIST.args(Component.text(serverName))
);
return 0;
}
if (server.getPlayer(player).isEmpty() && !Objects.equals(player, "all")) {
context.getSource().sendMessage(
CommandMessages.PLAYER_NOT_FOUND.args(Component.text(player))
);
return 0;
}
if (Objects.equals(player, "all")) {
for (Player p : server.getAllPlayers()) {
p.createConnectionRequest(server.getServer(serverName).get()).fireAndForget();
}
return 1;
}
server.getPlayer(player).get().createConnectionRequest(
server.getServer(serverName).get()
).fireAndForget();
return 1;
}
}

Datei anzeigen

@ -35,6 +35,7 @@ velocity.command.generic-error=An error occurred while running this command.
velocity.command.command-does-not-exist=This command does not exist. velocity.command.command-does-not-exist=This command does not exist.
velocity.command.players-only=Only players can run this command. velocity.command.players-only=Only players can run this command.
velocity.command.server-does-not-exist=The specified server {0} does not exist. velocity.command.server-does-not-exist=The specified server {0} does not exist.
velocity.command.player-not-found=The specified player {0} does not exist.
velocity.command.server-current-server=You are currently connected to {0}. velocity.command.server-current-server=You are currently connected to {0}.
velocity.command.server-too-many=There are too many servers set up. Use tab completion to view all servers available. velocity.command.server-too-many=There are too many servers set up. Use tab completion to view all servers available.
velocity.command.server-available=Available servers: velocity.command.server-available=Available servers:
@ -59,5 +60,6 @@ velocity.command.dump-success=Created an anonymised report containing useful inf
velocity.command.dump-will-expire=This link will expire in a few days. velocity.command.dump-will-expire=This link will expire in a few days.
velocity.command.dump-server-error=An error occurred on the Velocity servers and the dump could not be completed. Please contact the Velocity staff about this problem and provide the details about this error from the Velocity console or server log. velocity.command.dump-server-error=An error occurred on the Velocity servers and the dump could not be completed. Please contact the Velocity staff about this problem and provide the details about this error from the Velocity console or server log.
velocity.command.dump-offline=Likely cause: Invalid system DNS settings or no internet connection velocity.command.dump-offline=Likely cause: Invalid system DNS settings or no internet connection
velocity.command.send-usage=/send <player> <server>
# Kick # Kick
velocity.kick.shutdown=Proxy shutting down. velocity.kick.shutdown=Proxy shutting down.

Datei anzeigen

@ -35,6 +35,7 @@ velocity.command.command-does-not-exist=Este comando no existe.
velocity.command.players-only=Solo los jugadores pueden ejecutar este comando. velocity.command.players-only=Solo los jugadores pueden ejecutar este comando.
velocity.command.server-does-not-exist=El servidor especificado {0} no existe. velocity.command.server-does-not-exist=El servidor especificado {0} no existe.
velocity.command.server-current-server=Estás conectado a {0}. velocity.command.server-current-server=Estás conectado a {0}.
velocity.command.player-not-found=El jugador especificado {0} no existe.
velocity.command.server-too-many=Hay demasiados servidores registrados. Usa la finalización con tabulación para ver todos los servidores disponibles. velocity.command.server-too-many=Hay demasiados servidores registrados. Usa la finalización con tabulación para ver todos los servidores disponibles.
velocity.command.server-available=Servidores disponibles\: velocity.command.server-available=Servidores disponibles\:
velocity.command.server-tooltip-player-online={0} jugador conectado velocity.command.server-tooltip-player-online={0} jugador conectado
@ -58,3 +59,4 @@ velocity.command.dump-success=Se ha creado un informe anónimo que contiene info
velocity.command.dump-will-expire=Este enlace caducará en unos días. velocity.command.dump-will-expire=Este enlace caducará en unos días.
velocity.command.dump-server-error=Se ha producido un error en los servidores de Velocity y la subida no se ha podido completar. Notifica al equipo de Velocity sobre este problema y proporciona los detalles sobre este error disponibles en el archivo de registro o la consola de tu servidor Velocity. velocity.command.dump-server-error=Se ha producido un error en los servidores de Velocity y la subida no se ha podido completar. Notifica al equipo de Velocity sobre este problema y proporciona los detalles sobre este error disponibles en el archivo de registro o la consola de tu servidor Velocity.
velocity.command.dump-offline=Causa probable\: la configuración DNS del sistema no es válida o no hay conexión a internet velocity.command.dump-offline=Causa probable\: la configuración DNS del sistema no es válida o no hay conexión a internet
velocity.command.send-usage=/send <player> <server>