From 73c8479a8ad2b60c215267b12c5dd0a06573fd99 Mon Sep 17 00:00:00 2001 From: Luccboy <58391278+Luccboy@users.noreply.github.com> Date: Sun, 29 Oct 2023 19:42:40 +0100 Subject: [PATCH] Allow sending all players from current server (#1133) --- .../proxy/command/builtin/SendCommand.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/SendCommand.java b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/SendCommand.java index 555716130d..a35b5045ae 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/SendCommand.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/command/builtin/SendCommand.java @@ -70,6 +70,10 @@ public void register() { if ("all".regionMatches(true, 0, argument, 0, argument.length())) { builder.suggest("all"); } + if ("current".regionMatches(true, 0, argument, 0, argument.length()) + && context.getSource() instanceof Player) { + builder.suggest("current"); + } return builder.buildFuture(); }) .executes(this::usage) @@ -113,7 +117,8 @@ private int send(CommandContext context) { return 0; } - if (server.getPlayer(player).isEmpty() && !Objects.equals(player, "all")) { + if (server.getPlayer(player).isEmpty() + && !Objects.equals(player, "all") && !Objects.equals(player, "current")) { context.getSource().sendMessage( CommandMessages.PLAYER_NOT_FOUND.args(Component.text(player)) ); @@ -127,6 +132,22 @@ private int send(CommandContext context) { return 1; } + if (Objects.equals(player, "current")) { + if (!(context.getSource() instanceof Player)) { + context.getSource().sendMessage(CommandMessages.PLAYERS_ONLY); + return 0; + } + + Player source = (Player) context.getSource(); + if (source.getCurrentServer().isPresent()) { + for (Player p : source.getCurrentServer().get().getServer().getPlayersConnected()) { + p.createConnectionRequest(server.getServer(serverName).get()).fireAndForget(); + } + return 1; + } + return 0; + } + server.getPlayer(player).get().createConnectionRequest( server.getServer(serverName).get() ).fireAndForget();