mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Adjust player list caching
This commit is contained in:
1 parent
7b07e45742
commit
c22276908a
5 files changed
+59
-52
No files matched your search
@@ -21,24 +21,23 @@ public class TpAllCommand extends CommandBase {
|
||||
return;
|
||||
}
|
||||
|
||||
// Update cached players
|
||||
plugin.getCache().updateOnlinePlayerList(plugin, onlineUser);
|
||||
// Determine players to teleport and teleport them
|
||||
plugin.getCache().fetchAndCacheGlobalPlayerList(plugin, onlineUser).thenAccept(fetchedPlayers -> {
|
||||
final List<String> players = fetchedPlayers.stream()
|
||||
.filter(userName -> !userName.equalsIgnoreCase(onlineUser.username)).toList();
|
||||
if (players.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_no_players_online").ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine players to teleport
|
||||
final List<String> players = plugin.getCache().players.stream()
|
||||
.filter(userName -> !userName.equalsIgnoreCase(onlineUser.username)).toList();
|
||||
if (players.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_no_players_online").ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
// Send a message
|
||||
plugin.getLocales().getLocale("teleporting_all_players", Integer.toString(players.size()))
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
|
||||
// Send a message
|
||||
plugin.getLocales().getLocale("teleporting_all_players", Integer.toString(players.size()))
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
|
||||
// Teleport every player
|
||||
players.forEach(playerName -> plugin.getTeleportManager()
|
||||
.teleportPlayerByName(playerName, onlineUser.getPosition(), onlineUser, false));
|
||||
// Teleport every player
|
||||
players.forEach(playerName -> plugin.getTeleportManager()
|
||||
.teleportPlayerByName(playerName, onlineUser.getPosition(), onlineUser, false));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,35 +25,33 @@ public class TpaAllCommand extends CommandBase {
|
||||
return;
|
||||
}
|
||||
|
||||
// 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.equalsIgnoreCase(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);
|
||||
// Determine players to teleport and teleport them
|
||||
plugin.getCache().fetchAndCacheGlobalPlayerList(plugin, onlineUser).thenAccept(playerList -> {
|
||||
final List<String> players = plugin.getCache().players.stream()
|
||||
.filter(userName -> !userName.equalsIgnoreCase(onlineUser.username)).toList();
|
||||
if (players.isEmpty()) {
|
||||
plugin.getLocales().getLocale("error_no_players_online").ifPresent(onlineUser::sendMessage);
|
||||
return;
|
||||
}
|
||||
plugin.getLocales().getLocale("tpaall_request_sent", Integer.toString(counter.get()))
|
||||
.ifPresent(onlineUser::sendMessage);
|
||||
});
|
||||
|
||||
// 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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user