Adjust caching mechanism for player lists

This commit is contained in:
William committed 2022-12-18 14:09:04 +00:00
1 parent 0c1ad832ea
commit ccda814c88
3 files changed
+20 -21

No files matched your search

+1 -1
View File
@@ -15,7 +15,7 @@ dependencies {
compileOnly 'net.william278:Annotaml:2.0' compileOnly 'net.william278:Annotaml:2.0'
compileOnly 'net.william278:DesertWell:1.1' compileOnly 'net.william278:DesertWell:1.1'
compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1' compileOnly 'com.github.MilkBowl:VaultAPI:1.7.1'
compileOnly 'com.github.Emibergo02:RedisEconomy:2.1-SNAPSHOT' compileOnly 'com.github.Emibergo02:RedisEconomy:9f4f9c86f4'
compileOnly 'us.dynmap:dynmap-api:3.1' compileOnly 'us.dynmap:dynmap-api:3.1'
testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:1.5.2' testImplementation 'com.github.seeseemelk:MockBukkit-v1.16:1.5.2'
@@ -41,7 +41,7 @@ public class Cache {
/** /**
* Cached player list * 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 * 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.homes = new HashMap<>();
this.publicHomes = new HashMap<>(); this.publicHomes = new HashMap<>();
this.warps = new ArrayList<>(); this.warps = new ArrayList<>();
this.players = new ArrayList<>(); this.players = new HashSet<>();
this.privateHomeLists = new HashMap<>(); this.privateHomeLists = new HashMap<>();
this.publicHomeLists = new HashMap<>(); this.publicHomeLists = new HashMap<>();
this.warpLists = new HashMap<>(); this.warpLists = new HashMap<>();
@@ -104,22 +104,23 @@ public class Cache {
* *
* @param plugin the implementing plugin * @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) { if (plugin.getSettings().crossServer) {
return plugin.getMessenger().getOnlinePlayerNames(requester).thenApply(returnedPlayerList -> { return plugin.getMessenger()
players.clear(); .getOnlinePlayerNames(requester)
players.addAll(List.of(returnedPlayerList)); .thenApply(networkedPlayers -> {
return players; players.addAll(Set.of(networkedPlayers));
}); return players;
} else { });
players.clear();
players.addAll(plugin.getOnlinePlayers()
.stream()
.filter(player -> !player.isVanished())
.map(onlineUser -> onlineUser.username)
.toList());
return CompletableFuture.completedFuture(players);
} }
return CompletableFuture.completedFuture(players);
} }
/** /**
@@ -40,10 +40,8 @@ public class TpCommand extends CommandBase implements TabCompletable, ConsoleExe
// Find the online user to teleport // Find the online user to teleport
plugin.getCache().updatePlayerListCache(plugin, onlineUser).thenRun(() -> { plugin.getCache().updatePlayerListCache(plugin, onlineUser).thenRun(() -> {
// Get the list of potential teleports, filtered against vanished players, but ensuring the executor is in the list // 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; final Set<String> players = plugin.getCache().players;
if (!players.contains(onlineUser.username)) { players.add(onlineUser.username);
players.add(onlineUser.username);
}
// Find the player to teleport // Find the player to teleport
final String playerToTeleport = players.stream() final String playerToTeleport = players.stream()