mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 14:38:53 +00:00
Add /tpaall
This commit is contained in:
1 parent
0bfd990dee
commit
5552db2de0
5 files changed
+58
-2
No files matched your search
@@ -34,6 +34,7 @@ public enum BukkitCommandType {
|
|||||||
TP_IGNORE_COMMAND(new TpIgnoreCommand(BukkitHuskHomes.getInstance())),
|
TP_IGNORE_COMMAND(new TpIgnoreCommand(BukkitHuskHomes.getInstance())),
|
||||||
TP_OFFLINE_COMMAND(new TpOfflineCommand(BukkitHuskHomes.getInstance())),
|
TP_OFFLINE_COMMAND(new TpOfflineCommand(BukkitHuskHomes.getInstance())),
|
||||||
TP_ALL_COMMAND(new TpAllCommand(BukkitHuskHomes.getInstance())),
|
TP_ALL_COMMAND(new TpAllCommand(BukkitHuskHomes.getInstance())),
|
||||||
|
TPA_ALL_COMMAND(new TpaAllCommand(BukkitHuskHomes.getInstance())),
|
||||||
SPAWN_COMMAND(new SpawnCommand(BukkitHuskHomes.getInstance())),
|
SPAWN_COMMAND(new SpawnCommand(BukkitHuskHomes.getInstance())),
|
||||||
SET_SPAWN_COMMAND(new SetSpawnCommand(BukkitHuskHomes.getInstance())),
|
SET_SPAWN_COMMAND(new SetSpawnCommand(BukkitHuskHomes.getInstance())),
|
||||||
BACK_COMMAND(new BackCommand(BukkitHuskHomes.getInstance()));
|
BACK_COMMAND(new BackCommand(BukkitHuskHomes.getInstance()));
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ commands:
|
|||||||
usage: /tpoffline <player>
|
usage: /tpoffline <player>
|
||||||
tpall:
|
tpall:
|
||||||
usage: /tpall [page]
|
usage: /tpall [page]
|
||||||
|
tpaall:
|
||||||
|
usage: /tpaall [page]
|
||||||
spawn:
|
spawn:
|
||||||
usage: /spawn
|
usage: /spawn
|
||||||
setspawn:
|
setspawn:
|
||||||
|
|||||||
@@ -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<String> 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<CompletableFuture<Void>> 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);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -127,7 +127,7 @@ public enum Permission {
|
|||||||
/**
|
/**
|
||||||
* Lets the user send a teleport request asking everyone to teleport to them ({@code /tpaall})
|
* 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})
|
* Lets the user randomly teleport in the world they are in ({@code /rtp})
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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)'
|
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)'
|
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)'
|
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)'
|
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%)'
|
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%)'
|
||||||
|
|||||||
Reference in new issue
Block a user