mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Adjust caching mechanism for player lists
This commit is contained in:
1 parent
0c1ad832ea
commit
ccda814c88
3 files changed
+20
-21
No files matched your search
@@ -41,7 +41,7 @@ public class Cache {
|
||||
/**
|
||||
* Cached player list
|
||||
*/
|
||||
public final List<String> players;
|
||||
public final Set<String> players;
|
||||
|
||||
/**
|
||||
* Cached lists of private homes for pagination, mapped to the username of the home owner
|
||||
@@ -75,7 +75,7 @@ public class Cache {
|
||||
this.homes = new HashMap<>();
|
||||
this.publicHomes = new HashMap<>();
|
||||
this.warps = new ArrayList<>();
|
||||
this.players = new ArrayList<>();
|
||||
this.players = new HashSet<>();
|
||||
this.privateHomeLists = new HashMap<>();
|
||||
this.publicHomeLists = new HashMap<>();
|
||||
this.warpLists = new HashMap<>();
|
||||
@@ -104,22 +104,23 @@ public class Cache {
|
||||
*
|
||||
* @param plugin the implementing plugin
|
||||
*/
|
||||
public CompletableFuture<List<String>> updatePlayerListCache(@NotNull HuskHomes plugin, @NotNull OnlineUser requester) {
|
||||
public CompletableFuture<Set<String>> updatePlayerListCache(@NotNull HuskHomes plugin, @NotNull OnlineUser requester) {
|
||||
players.clear();
|
||||
players.addAll(plugin.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(player -> !player.isVanished())
|
||||
.map(onlineUser -> onlineUser.username)
|
||||
.toList());
|
||||
|
||||
if (plugin.getSettings().crossServer) {
|
||||
return plugin.getMessenger().getOnlinePlayerNames(requester).thenApply(returnedPlayerList -> {
|
||||
players.clear();
|
||||
players.addAll(List.of(returnedPlayerList));
|
||||
return players;
|
||||
});
|
||||
} else {
|
||||
players.clear();
|
||||
players.addAll(plugin.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(player -> !player.isVanished())
|
||||
.map(onlineUser -> onlineUser.username)
|
||||
.toList());
|
||||
return CompletableFuture.completedFuture(players);
|
||||
return plugin.getMessenger()
|
||||
.getOnlinePlayerNames(requester)
|
||||
.thenApply(networkedPlayers -> {
|
||||
players.addAll(Set.of(networkedPlayers));
|
||||
return players;
|
||||
});
|
||||
}
|
||||
return CompletableFuture.completedFuture(players);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,10 +40,8 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
|
||||
// Find the online user to teleport
|
||||
plugin.getCache().updatePlayerListCache(plugin, onlineUser).thenRun(() -> {
|
||||
// Get the list of potential teleports, filtered against vanished players, but ensuring the executor is in the list
|
||||
final List<String> players = plugin.getCache().players;
|
||||
if (!players.contains(onlineUser.username)) {
|
||||
players.add(onlineUser.username);
|
||||
}
|
||||
final Set<String> players = plugin.getCache().players;
|
||||
players.add(onlineUser.username);
|
||||
|
||||
// Find the player to teleport
|
||||
final String playerToTeleport = players.stream()
|
||||
|
||||
Reference in new issue
Block a user