diff --git a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java index 58defb37..94202b5c 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java +++ b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java @@ -34,6 +34,7 @@ public enum BukkitCommandType { TP_IGNORE_COMMAND(new TpIgnoreCommand(BukkitHuskHomes.getInstance())), TP_OFFLINE_COMMAND(new TpOfflineCommand(BukkitHuskHomes.getInstance())), TP_ALL_COMMAND(new TpAllCommand(BukkitHuskHomes.getInstance())), + TPA_ALL_COMMAND(new TpaAllCommand(BukkitHuskHomes.getInstance())), SPAWN_COMMAND(new SpawnCommand(BukkitHuskHomes.getInstance())), SET_SPAWN_COMMAND(new SetSpawnCommand(BukkitHuskHomes.getInstance())), BACK_COMMAND(new BackCommand(BukkitHuskHomes.getInstance())); diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index ca739c30..161d57ec 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -63,6 +63,8 @@ commands: usage: /tpoffline tpall: usage: /tpall [page] + tpaall: + usage: /tpaall [page] spawn: usage: /spawn setspawn: diff --git a/common/src/main/java/net/william278/huskhomes/command/TpaAllCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpaAllCommand.java new file mode 100644 index 00000000..98cbd27b --- /dev/null +++ b/common/src/main/java/net/william278/huskhomes/command/TpaAllCommand.java @@ -0,0 +1,53 @@ +package net.william278.huskhomes.command; + +import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.player.OnlineUser; +import net.william278.huskhomes.request.TeleportRequest; +import net.william278.huskhomes.util.Permission; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicInteger; + +public class TpaAllCommand extends CommandBase { + + protected TpaAllCommand(@NotNull HuskHomes implementor) { + super("tpaall", Permission.COMMAND_TPA_ALL, implementor); + } + + @Override + public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { + // Update cached players + plugin.getCache().updateOnlinePlayerList(plugin, onlineUser); + + // Determine players to send teleport requests to + final List players = plugin.getCache().players.stream() + .filter(userName -> !userName.equals(onlineUser.username)).toList(); + if (players.isEmpty()) { + plugin.getLocales().getLocale("error_no_players_online").ifPresent(onlineUser::sendMessage); + return; + } + + // Send a teleport request to every player + final AtomicInteger counter = new AtomicInteger(0); + final List> sentRequestsFuture = new ArrayList<>(); + players.forEach(playerName -> sentRequestsFuture.add(plugin.getRequestManager() + .sendTeleportRequest(onlineUser, playerName, TeleportRequest.RequestType.TPA_HERE) + .thenAccept(sent -> counter.addAndGet(sent ? 1 : 0)))); + + // Send a message when all requests have been sent + CompletableFuture.allOf(sentRequestsFuture.toArray(new CompletableFuture[0])).thenRun(() -> { + if (counter.get() == 0) { + plugin.getLocales().getLocale("error_no_players_online") + .ifPresent(onlineUser::sendMessage); + return; + } + plugin.getLocales().getLocale("tpaall_request_sent", Integer.toString(counter.get())) + .ifPresent(onlineUser::sendMessage); + }); + + } + +} diff --git a/common/src/main/java/net/william278/huskhomes/util/Permission.java b/common/src/main/java/net/william278/huskhomes/util/Permission.java index 9d908f9a..e44bcc0e 100644 --- a/common/src/main/java/net/william278/huskhomes/util/Permission.java +++ b/common/src/main/java/net/william278/huskhomes/util/Permission.java @@ -127,7 +127,7 @@ public enum Permission { /** * Lets the user send a teleport request asking everyone to teleport to them ({@code /tpaall}) */ - COMMAND_TPAALL("huskhomes.command.tpaall", DefaultAccess.OPERATORS), + COMMAND_TPA_ALL("huskhomes.command.tpaall", DefaultAccess.OPERATORS), /** * Lets the user randomly teleport in the world they are in ({@code /rtp}) */ diff --git a/common/src/main/resources/locales/en-gb.yml b/common/src/main/resources/locales/en-gb.yml index 4aeb894c..3627a6be 100644 --- a/common/src/main/resources/locales/en-gb.yml +++ b/common/src/main/resources/locales/en-gb.yml @@ -73,7 +73,7 @@ warp_deleted: '[Successfully deleted the warp,](#00fb9a) [%1%](#00fb9a bold)' tpa_request_sent: '[You sent a teleport request asking to teleport to](#00fb9a) [%1%](#00fb9a bold)[.](#00fb9a)' tpahere_request_sent: '[You sent a teleport request asking](#00fb9a) [%1%](#00fb9a bold) [to teleport to you.](#00fb9a)' -tpaall_request_sent: '[You sent a teleport request asking everyone to teleport to you.](#00fb9a)' +tpaall_request_sent: '[You sent a request to](#00fb9a) [%1%](#00fb9a bold) [players asking them to teleport to you.](#00fb9a)' tpa_request_received: '[%1%](#00fb9a bold) [has requested to teleport to you.](#00fb9a)' tpahere_request_received: '[%1%](#00fb9a bold) [has requested that you teleport to them.](#00fb9a)' teleport_request_buttons: '[Options:](gray) [[✔ Accept…]](#00fb9a show_text=�fb9a&Accept teleport request\n&8Click to accept %1%''s request run_command=/tpaccept %1%) [[❌ Decline…]](#ff3300 show_text=&#ff3300&Decline teleport request\n&8Click to decline %1%''s request run_command=/tpdeny %1%)'