Add player-filter to plugin-state

This commit is contained in:
Lukas Rieger (Blue) 2022-07-04 13:07:56 +02:00
parent 03f58c7739
commit c4e7349c54
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
5 changed files with 30 additions and 9 deletions

View File

@ -8,6 +8,8 @@ import de.bluecolored.bluemap.core.logger.Logger;
import java.io.IOException;
import java.io.StringWriter;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.function.Supplier;
public class LivePlayersDataSupplier implements Supplier<String> {
@ -15,11 +17,13 @@ public class LivePlayersDataSupplier implements Supplier<String> {
private final ServerInterface server;
private final PluginConfig config;
private final String worldId;
private final Predicate<UUID> playerFilter;
public LivePlayersDataSupplier(ServerInterface server, PluginConfig config, String worldId) {
public LivePlayersDataSupplier(ServerInterface server, PluginConfig config, String worldId, Predicate<UUID> playerFilter) {
this.server = server;
this.config = config;
this.worldId = worldId;
this.playerFilter = playerFilter;
}
@Override
@ -41,6 +45,7 @@ public class LivePlayersDataSupplier implements Supplier<String> {
if (config.isHideSneaking() && player.isSneaking()) continue;
if (config.getHiddenGameModes().contains(player.getGamemode().getId())) continue;
if (config.isHideDifferentWorld() && !isCorrectWorld) continue;
if (!this.playerFilter.test(player.getUuid())) continue;
json.beginObject();
json.name("uuid").value(player.getUuid().toString());

View File

@ -53,6 +53,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.regex.Pattern;
@DebugDump
@ -162,7 +163,7 @@ public class Plugin implements ServerEventListener {
routingRequestHandler.register(
"maps/" + Pattern.quote(map.getId()) + "/(.*)",
"$1",
new MapRequestHandler(map, serverInterface, pluginConfig)
new MapRequestHandler(map, serverInterface, pluginConfig, Predicate.not(pluginState::isPlayerHidden))
);
}

View File

@ -27,8 +27,7 @@ package de.bluecolored.bluemap.common.plugin;
import de.bluecolored.bluemap.core.map.BmMap;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
@SuppressWarnings("FieldMayBeFinal")
@ConfigSerializable
@ -36,6 +35,7 @@ public class PluginState {
private boolean renderThreadsEnabled = true;
private Map<String, MapState> maps = new HashMap<>();
private Set<UUID> hiddenPlayers = new HashSet<>();
public boolean isRenderThreadsEnabled() {
return renderThreadsEnabled;
@ -49,6 +49,18 @@ public class PluginState {
return maps.computeIfAbsent(map.getId(), k -> new MapState());
}
public void addHiddenPlayer(UUID player) {
hiddenPlayers.add(player);
}
public void removeHiddenPlayer(UUID player) {
hiddenPlayers.remove(player);
}
public boolean isPlayerHidden(UUID player) {
return hiddenPlayers.contains(player);
}
@ConfigSerializable
public static class MapState {

View File

@ -6,18 +6,21 @@ import de.bluecolored.bluemap.common.serverinterface.ServerInterface;
import de.bluecolored.bluemap.core.map.BmMap;
import de.bluecolored.bluemap.core.storage.Storage;
import java.util.UUID;
import java.util.function.Predicate;
public class MapRequestHandler extends RoutingRequestHandler {
public MapRequestHandler(BmMap map, ServerInterface serverInterface, PluginConfig pluginConfig) {
this(map.getId(), map.getWorldId(), map.getStorage(), serverInterface, pluginConfig);
public MapRequestHandler(BmMap map, ServerInterface serverInterface, PluginConfig pluginConfig, Predicate<UUID> playerFilter) {
this(map.getId(), map.getWorldId(), map.getStorage(), serverInterface, pluginConfig, playerFilter);
}
public MapRequestHandler(String mapId, String worldId, Storage mapStorage, ServerInterface serverInterface, PluginConfig pluginConfig) {
public MapRequestHandler(String mapId, String worldId, Storage mapStorage, ServerInterface serverInterface, PluginConfig pluginConfig, Predicate<UUID> playerFilter) {
register(".*", new MapStorageRequestHandler(mapId, mapStorage));
register("live/players", "", new JsonDataRequestHandler(
new CachedRateLimitDataSupplier(
new LivePlayersDataSupplier(serverInterface, pluginConfig, worldId),
new LivePlayersDataSupplier(serverInterface, pluginConfig, worldId, playerFilter),
1000)
));
}

View File

@ -197,7 +197,7 @@ public class BlueMapCLI implements ServerInterface {
routingRequestHandler.register(
"maps/" + Pattern.quote(mapId) + "/(.*)",
"$1",
new MapRequestHandler(mapId, worldId, blueMap.getStorage(mapConfig.getStorage()), this, blueMap.getConfigs().getPluginConfig())
new MapRequestHandler(mapId, worldId, blueMap.getStorage(mapConfig.getStorage()), this, blueMap.getConfigs().getPluginConfig(), uuid -> true)
);
}