Skip to content

Commit

Permalink
Allow sending all players from current server (#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luccboy authored Oct 29, 2023
1 parent 67d5e77 commit f87b05a
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 f87b05a

Please sign in to comment.