Add a way to register externally rendered or static maps without a world

This commit is contained in:
Lukas Rieger (Blue) 2022-08-03 12:54:03 +02:00
parent fa361043c5
commit dafabac5bb
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
6 changed files with 63 additions and 37 deletions

View File

@ -174,8 +174,16 @@ private synchronized void loadWorldsAndMaps() throws ConfigurationException, Int
String id = entry.getKey();
String name = mapConfig.getName();
if (name == null) name = id;
Path worldFolder = mapConfig.getWorld();
// if there is no world configured, we assume the map is static, or supplied from a different server
if (worldFolder == null) {
Logger.global.logInfo("The map '" + name + "' has no world configured. The map will be displayed, but not updated!");
continue;
}
if (!Files.isDirectory(worldFolder)) {
throw new ConfigurationException("Failed to load map '" + id + "': \n" +
"'" + worldFolder.toAbsolutePath().normalize() + "' does not exist or is no directory!\n" +
@ -380,7 +388,9 @@ public synchronized ResourcePack getResourcePack() throws ConfigurationException
private Collection<Path> getWorldFolders() {
Set<Path> folders = new HashSet<>();
for (MapConfig mapConfig : configs.getMapConfigs().values()) {
Path folder = mapConfig.getWorld().toAbsolutePath().normalize();
Path folder = mapConfig.getWorld();
if (folder == null) continue;
folder = folder.toAbsolutePath().normalize();
if (Files.isDirectory(folder)) {
folders.add(folder);
}

View File

@ -4,9 +4,9 @@
import com.flowpowered.math.vector.Vector3i;
import de.bluecolored.bluemap.api.debug.DebugDump;
import de.bluecolored.bluemap.core.map.MapSettings;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Required;
import java.nio.file.Path;
import java.util.Optional;
@ -18,8 +18,7 @@ public class MapConfig implements MapSettings {
private String name = null;
@Required
private Path world = Path.of("world");
private Path world = null;
private int sorting = 0;
@ -58,10 +57,12 @@ public class MapConfig implements MapSettings {
private int lowresPointsPerHiresTile = 4;
private int lowresPointsPerLowresTile = 50;
@Nullable
public String getName() {
return name;
}
@Nullable
public Path getWorld() {
return world;
}
@ -116,6 +117,7 @@ public boolean isIgnoreMissingLightData() {
return ignoreMissingLightData;
}
@Nullable
public ConfigurationNode getMarkerSets() {
return markerSets;
}

View File

@ -5,6 +5,7 @@
import de.bluecolored.bluemap.common.serverinterface.Player;
import de.bluecolored.bluemap.common.serverinterface.ServerInterface;
import de.bluecolored.bluemap.core.logger.Logger;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.StringWriter;
@ -16,7 +17,7 @@ public class LivePlayersDataSupplier implements Supplier<String> {
private final ServerInterface server;
private final PluginConfig config;
private final String worldId;
@Nullable private final String worldId;
private final Predicate<UUID> playerFilter;
public LivePlayersDataSupplier(ServerInterface server, PluginConfig config, String worldId, Predicate<UUID> playerFilter) {

View File

@ -46,6 +46,7 @@
import de.bluecolored.bluemap.core.map.BmMap;
import de.bluecolored.bluemap.core.metrics.Metrics;
import de.bluecolored.bluemap.core.storage.MetaType;
import de.bluecolored.bluemap.core.storage.Storage;
import de.bluecolored.bluemap.core.world.World;
import org.spongepowered.configurate.gson.GsonConfigurationLoader;
import org.spongepowered.configurate.serialize.SerializationException;
@ -167,11 +168,23 @@ public void load() throws IOException {
routingRequestHandler.register(".*", new FileRequestHandler(webroot));
// map route
for (BmMap map : maps.values()) {
for (var mapConfigEntry : getConfigs().getMapConfigs().entrySet()) {
String id = mapConfigEntry.getKey();
MapConfig mapConfig = mapConfigEntry.getValue();
MapRequestHandler mapRequestHandler;
BmMap map = maps.get(id);
if (map != null) {
mapRequestHandler = new MapRequestHandler(map, serverInterface, pluginConfig, Predicate.not(pluginState::isPlayerHidden));
} else {
Storage storage = blueMap.getStorage(mapConfig.getStorage());
mapRequestHandler = new MapRequestHandler(id, storage);
}
routingRequestHandler.register(
"maps/" + Pattern.quote(map.getId()) + "/(.*)",
"maps/" + Pattern.quote(id) + "/(.*)",
"$1",
new MapRequestHandler(map, serverInterface, pluginConfig, Predicate.not(pluginState::isPlayerHidden))
mapRequestHandler
);
}

View File

@ -1,39 +1,46 @@
package de.bluecolored.bluemap.common.web;
import de.bluecolored.bluemap.api.markers.MarkerSet;
import de.bluecolored.bluemap.common.config.PluginConfig;
import de.bluecolored.bluemap.common.live.LiveMarkersDataSupplier;
import de.bluecolored.bluemap.common.live.LivePlayersDataSupplier;
import de.bluecolored.bluemap.common.serverinterface.ServerInterface;
import de.bluecolored.bluemap.core.map.BmMap;
import de.bluecolored.bluemap.core.storage.Storage;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.function.Supplier;
public class MapRequestHandler extends RoutingRequestHandler {
public MapRequestHandler(BmMap map, ServerInterface serverInterface, PluginConfig pluginConfig,
Predicate<UUID> playerFilter) {
this(map.getId(), map.getWorldId(), map.getStorage(), map.getMarkerSets(),
serverInterface, pluginConfig, playerFilter);
public MapRequestHandler(BmMap map, ServerInterface serverInterface, PluginConfig pluginConfig, Predicate<UUID> playerFilter) {
this(map.getId(), map.getStorage(),
new LivePlayersDataSupplier(serverInterface, pluginConfig, map.getWorldId(), playerFilter),
new LiveMarkersDataSupplier(map.getMarkerSets()));
}
public MapRequestHandler(String mapId, String worldId, Storage mapStorage, Map<String, MarkerSet> markerSets,
ServerInterface serverInterface, PluginConfig pluginConfig, Predicate<UUID> playerFilter) {
public MapRequestHandler(String mapId, Storage mapStorage) {
this(mapId, mapStorage, null, null);
}
public MapRequestHandler(String mapId, Storage mapStorage,
@Nullable Supplier<String> livePlayersDataSupplier,
@Nullable Supplier<String> liveMarkerDataSupplier) {
register(".*", new MapStorageRequestHandler(mapId, mapStorage));
register("live/players", "", new JsonDataRequestHandler(
new CachedRateLimitDataSupplier(
new LivePlayersDataSupplier(serverInterface, pluginConfig, worldId, playerFilter),
1000)
));
register("live/markers", "", new JsonDataRequestHandler(
new CachedRateLimitDataSupplier(
new LiveMarkersDataSupplier(markerSets),
10000)
));
if (livePlayersDataSupplier != null) {
register("live/players", "", new JsonDataRequestHandler(
new CachedRateLimitDataSupplier(livePlayersDataSupplier,1000)
));
}
if (liveMarkerDataSupplier != null) {
register("live/markers", "", new JsonDataRequestHandler(
new CachedRateLimitDataSupplier(liveMarkerDataSupplier,10000)
));
}
}
}

View File

@ -29,7 +29,6 @@
import de.bluecolored.bluemap.common.MissingResourcesException;
import de.bluecolored.bluemap.common.config.BlueMapConfigs;
import de.bluecolored.bluemap.common.config.ConfigurationException;
import de.bluecolored.bluemap.common.config.MapConfig;
import de.bluecolored.bluemap.common.config.WebserverConfig;
import de.bluecolored.bluemap.common.plugin.RegionFileWatchService;
import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask;
@ -48,6 +47,7 @@
import de.bluecolored.bluemap.core.logger.LoggerLogger;
import de.bluecolored.bluemap.core.map.BmMap;
import de.bluecolored.bluemap.core.metrics.Metrics;
import de.bluecolored.bluemap.core.storage.Storage;
import org.apache.commons.cli.*;
import org.apache.commons.lang3.time.DurationFormatUtils;
@ -80,11 +80,6 @@ public void renderMaps(BlueMapService blueMap, boolean watch, boolean forceRende
//load maps
Map<String, BmMap> maps = blueMap.getMaps();
//write static markers
for (BmMap map : maps.values()) {
}
//watcher
List<RegionFileWatchService> regionFileWatchServices = new ArrayList<>();
if (watch) {
@ -194,15 +189,13 @@ public void startWebserver(BlueMapService blueMap, boolean verbose) throws IOExc
routingRequestHandler.register(".*", new FileRequestHandler(config.getWebroot()));
// map route
for (var entry : blueMap.getConfigs().getMapConfigs().entrySet()) {
String mapId = entry.getKey();
MapConfig mapConfig = entry.getValue();
String worldId = blueMap.getWorldId(mapConfig.getWorld());
for (var mapId : blueMap.getConfigs().getMapConfigs().keySet()) {
Storage storage = blueMap.getStorage(mapId);
routingRequestHandler.register(
"maps/" + Pattern.quote(mapId) + "/(.*)",
"$1",
new MapRequestHandler(mapId, worldId, blueMap.getStorage(mapConfig.getStorage()), Map.of(), this, blueMap.getConfigs().getPluginConfig(), uuid -> true)
new MapRequestHandler(mapId, storage)
);
}