Skip to content

Commit

Permalink
Allow sending all players from current server (PaperMC#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luccboy authored and skbeh committed Jan 17, 2024
1 parent a4ce82c commit 73c8479
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -113,7 +117,8 @@ private int send(CommandContext<CommandSource> 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))
);
Expand All @@ -127,6 +132,22 @@ private int send(CommandContext<CommandSource> 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();
Expand Down

0 comments on commit 73c8479

Please sign in to comment.