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 b525b8ce..58defb37 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java +++ b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommandType.java @@ -33,6 +33,7 @@ public enum BukkitCommandType { RTP_COMMAND(new RtpCommand(BukkitHuskHomes.getInstance())), TP_IGNORE_COMMAND(new TpIgnoreCommand(BukkitHuskHomes.getInstance())), TP_OFFLINE_COMMAND(new TpOfflineCommand(BukkitHuskHomes.getInstance())), + TP_ALL_COMMAND(new TpAllCommand(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 b9bddc7f..ca739c30 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -61,6 +61,8 @@ commands: usage: /tpignore tpoffline: usage: /tpoffline + tpall: + usage: /tpall [page] spawn: usage: /spawn setspawn: diff --git a/common/src/main/java/net/william278/huskhomes/command/TpAllCommand.java b/common/src/main/java/net/william278/huskhomes/command/TpAllCommand.java new file mode 100644 index 00000000..39d4f043 --- /dev/null +++ b/common/src/main/java/net/william278/huskhomes/command/TpAllCommand.java @@ -0,0 +1,35 @@ +package net.william278.huskhomes.command; + +import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.player.OnlineUser; +import net.william278.huskhomes.util.Permission; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class TpAllCommand extends CommandBase { + + protected TpAllCommand(@NotNull HuskHomes implementor) { + super("tpall", Permission.COMMAND_TPALL, implementor); + } + + @Override + public void onExecute(@NotNull OnlineUser onlineUser, @NotNull String[] args) { + // Update cached players + plugin.getCache().updateOnlinePlayerList(plugin, onlineUser); + + // Determine players to teleport + 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; + } + + // Teleport every player + players.forEach(playerName -> plugin.getTeleportManager() + .teleportPlayerByName(playerName, onlineUser.getPosition(), onlineUser)); + + } + +} 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 2fda7183..9d908f9a 100644 --- a/common/src/main/java/net/william278/huskhomes/util/Permission.java +++ b/common/src/main/java/net/william278/huskhomes/util/Permission.java @@ -120,6 +120,14 @@ public enum Permission { * Lets the user tp to where a user logged out ({@code /tpoffline [player_name]}) */ COMMAND_TPOFFLINE("huskhomes.command.tpoffline", DefaultAccess.OPERATORS), + /** + * Lets the user teleport everyone to their position ({@code /tpall}) + */ + COMMAND_TPALL("huskhomes.command.tpall", DefaultAccess.OPERATORS), + /** + * Lets the user send a teleport request asking everyone to teleport to them ({@code /tpaall}) + */ + COMMAND_TPAALL("huskhomes.command.tpaall", DefaultAccess.OPERATORS), /** * Lets the user randomly teleport in the world they are in ({@code /rtp}) */