mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-12-25 18:37:41 +01:00
Add player-filter to plugin-state
This commit is contained in:
parent
03f58c7739
commit
c4e7349c54
@ -8,6 +8,8 @@
|
||||
|
||||
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 String get() {
|
||||
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());
|
||||
|
@ -53,6 +53,7 @@
|
||||
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 void load() throws IOException {
|
||||
routingRequestHandler.register(
|
||||
"maps/" + Pattern.quote(map.getId()) + "/(.*)",
|
||||
"$1",
|
||||
new MapRequestHandler(map, serverInterface, pluginConfig)
|
||||
new MapRequestHandler(map, serverInterface, pluginConfig, Predicate.not(pluginState::isPlayerHidden))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,7 @@
|
||||
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 MapState getMapState(BmMap map) {
|
||||
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 {
|
||||
|
||||
|
@ -6,18 +6,21 @@
|
||||
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)
|
||||
));
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ public void startWebserver(BlueMapService blueMap, boolean verbose) throws IOExc
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user