Adjust player list caching

This commit is contained in:
William committed 2022-08-25 20:07:26 +01:00
1 parent 7b07e45742
commit c22276908a
5 files changed
+59 -52

No files matched your search

@@ -89,16 +89,18 @@ public class Cache {
}
/**
* Updates the cached list of online players
* Updates the cached list of online players and returns it
*
* @param plugin the implementing plugin
*/
public void updateOnlinePlayerList(@NotNull HuskHomes plugin, @NotNull OnlineUser requester) {
public CompletableFuture<List<String>> fetchAndCacheGlobalPlayerList(@NotNull HuskHomes plugin,
@NotNull OnlineUser requester) {
if (plugin.getSettings().crossServer) {
assert plugin.getNetworkMessenger() != null;
plugin.getNetworkMessenger().getOnlinePlayerNames(requester).thenAccept(returnedPlayerList -> {
return plugin.getNetworkMessenger().getOnlinePlayerNames(requester).thenApply(returnedPlayerList -> {
players.clear();
players.addAll(List.of(returnedPlayerList));
return players;
});
} else {
players.clear();
@@ -107,6 +109,7 @@ public class Cache {
.filter(player -> !player.isVanished())
.map(onlineUser -> onlineUser.username)
.toList());
return CompletableFuture.completedFuture(players);
}
}