|
24 | 24 | */ |
25 | 25 | package de.bluecolored.bluemap.cli; |
26 | 26 |
|
| 27 | +import de.bluecolored.bluemap.api.gson.MarkerGson; |
27 | 28 | import de.bluecolored.bluemap.common.BlueMapConfiguration; |
28 | 29 | import de.bluecolored.bluemap.common.BlueMapService; |
29 | 30 | import de.bluecolored.bluemap.common.MissingResourcesException; |
30 | 31 | import de.bluecolored.bluemap.common.addons.Addons; |
31 | 32 | import de.bluecolored.bluemap.common.api.BlueMapAPIImpl; |
32 | 33 | import de.bluecolored.bluemap.common.commands.TextFormat; |
33 | | -import de.bluecolored.bluemap.common.config.BlueMapConfigManager; |
34 | | -import de.bluecolored.bluemap.common.config.ConfigurationException; |
35 | | -import de.bluecolored.bluemap.common.config.CoreConfig; |
36 | | -import de.bluecolored.bluemap.common.config.WebserverConfig; |
| 34 | +import de.bluecolored.bluemap.common.config.*; |
37 | 35 | import de.bluecolored.bluemap.common.metrics.Metrics; |
38 | 36 | import de.bluecolored.bluemap.common.plugin.MapUpdateService; |
39 | | -import de.bluecolored.bluemap.common.rendermanager.*; |
| 37 | +import de.bluecolored.bluemap.common.rendermanager.MapUpdatePreparationTask; |
| 38 | +import de.bluecolored.bluemap.common.rendermanager.RenderManager; |
| 39 | +import de.bluecolored.bluemap.common.rendermanager.RenderTask; |
| 40 | +import de.bluecolored.bluemap.common.rendermanager.TileUpdateStrategy; |
40 | 41 | import de.bluecolored.bluemap.common.web.*; |
41 | 42 | import de.bluecolored.bluemap.common.web.http.HttpRequestHandler; |
42 | 43 | import de.bluecolored.bluemap.common.web.http.HttpServer; |
|
49 | 50 | import org.checkerframework.checker.nullness.qual.Nullable; |
50 | 51 |
|
51 | 52 | import java.io.IOException; |
| 53 | +import java.io.OutputStream; |
| 54 | +import java.io.OutputStreamWriter; |
| 55 | +import java.io.Writer; |
52 | 56 | import java.net.BindException; |
53 | 57 | import java.net.InetSocketAddress; |
54 | 58 | import java.net.UnknownHostException; |
| 59 | +import java.nio.charset.StandardCharsets; |
55 | 60 | import java.nio.file.Files; |
56 | 61 | import java.nio.file.Path; |
57 | 62 | import java.time.Duration; |
@@ -216,6 +221,34 @@ public void run() { |
216 | 221 | } |
217 | 222 | } |
218 | 223 |
|
| 224 | + public void updateMarkers(BlueMapService blueMap, @Nullable String mapsToUpdate) { |
| 225 | + Predicate<String> mapFilter = mapId -> true; |
| 226 | + if (mapsToUpdate != null) { |
| 227 | + Set<String> mapsToRenderSet = Set.of(mapsToUpdate.split(",")); |
| 228 | + mapFilter = mapsToRenderSet::contains; |
| 229 | + } |
| 230 | + |
| 231 | + for (Map.Entry<String, MapConfig> entry : blueMap.getConfig().getMapConfigs().entrySet()) { |
| 232 | + String mapId = entry.getKey(); |
| 233 | + MapConfig mapConfig = entry.getValue(); |
| 234 | + |
| 235 | + if (!mapFilter.test(mapId)) return; |
| 236 | + |
| 237 | + try { |
| 238 | + MapStorage storage = blueMap.getOrLoadStorage(mapConfig.getStorage()).map(mapId); |
| 239 | + try ( |
| 240 | + OutputStream out = storage.markers().write(); |
| 241 | + Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8) |
| 242 | + ) { |
| 243 | + MarkerGson.INSTANCE.toJson(mapConfig.parseMarkerSets(), writer); |
| 244 | + } |
| 245 | + Logger.global.logInfo("Updated markers for map '" + mapId + "'"); |
| 246 | + } catch (Exception ex) { |
| 247 | + Logger.global.logError("Failed to save markers for map '" + mapId + "'!", ex); |
| 248 | + } |
| 249 | + } |
| 250 | + } |
| 251 | + |
219 | 252 | public void startWebserver(BlueMapService blueMap, boolean verbose) throws IOException, ConfigurationException, InterruptedException { |
220 | 253 | Logger.global.logInfo("Starting webserver ..."); |
221 | 254 |
|
@@ -374,6 +407,11 @@ public static void main(String[] args) { |
374 | 407 | String mapsToRender = cmd.getOptionValue("m", null); |
375 | 408 | cli.renderMaps(blueMap, watch, force, generateWebappFiles, mapsToRender); |
376 | 409 | } else { |
| 410 | + if (cmd.hasOption("markers")) { |
| 411 | + noActions = false; |
| 412 | + String mapsToUpdate = cmd.getOptionValue("m", null); |
| 413 | + cli.updateMarkers(blueMap, mapsToUpdate); |
| 414 | + } |
377 | 415 | if (cmd.hasOption("g")) { |
378 | 416 | noActions = false; |
379 | 417 | blueMap.createOrUpdateWebApp(true); |
@@ -480,6 +518,8 @@ private static Options createOptions() { |
480 | 518 | options.addOption("f", "force-render", false, "Forces rendering everything, instead of only rendering chunks that have been modified since the last render"); |
481 | 519 | options.addOption("m", "maps", true, "A comma-separated list of map-id's that should be rendered. Example: 'world,nether'"); |
482 | 520 |
|
| 521 | + options.addOption(null, "markers", false, "Updates the map-markers based on the map configs"); |
| 522 | + |
483 | 523 | options.addOption("u", "watch", false, "Watches for file-changes after rendering and updates the map"); |
484 | 524 |
|
485 | 525 | options.addOption("V", "version", false, "Print the current BlueMap version"); |
|
0 commit comments