Skip to content

Commit

Permalink
Force save the markers to the storage when done
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed Nov 22, 2024
1 parent e2e92e2 commit ad1f6f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void run() {
}

for (BlueMapWorld apiWorld : api.getWorlds()) {
// no need to watch worlds that aren't rendered by bluemap anyway
if (apiWorld.getMaps().isEmpty()) continue;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.bluecolored.bluemap.api.BlueMapWorld;
import de.bluecolored.bluemap.api.markers.Marker;
import de.bluecolored.bluemap.api.markers.MarkerSet;
import de.bluecolored.bluemap.common.api.BlueMapMapImpl;
import de.bluecolored.bluemap.common.api.BlueMapWorldImpl;
import de.bluecolored.bluemap.core.util.WatchService;
import de.bluecolored.bluemap.core.world.Chunk;
Expand All @@ -26,6 +27,7 @@
* @see de.bluecolored.bluemap.common.plugin.MapUpdateService
*/
public class WorldWatcher extends Thread {
private final BlueMapWorld apiWorld;
private final World world;
private final WatchService<Vector2i> watchService;

Expand All @@ -40,6 +42,7 @@ public class WorldWatcher extends Thread {
private final Config config;

public WorldWatcher(BlueMapWorld apiWorld, Config config) throws IOException {
this.apiWorld = apiWorld;
this.world = ((BlueMapWorldImpl) apiWorld).world();
this.closed = false;
this.scheduledUpdates = new HashMap<>();
Expand Down Expand Up @@ -116,6 +119,10 @@ public void run() {
}
});
});

// Force save the markers to the storage
// This is especially important for the CLI, which otherwise would not save the markers for a long time
saveMarkers(); //TODO: Should be done less (only when all regions are done)
} catch (IOException e) {
logger.logError("Failed to get region" + regionPos, e);
}
Expand All @@ -138,4 +145,8 @@ public void close() {
logger.logError("Failed to close watch service", e);
}
}

private void saveMarkers() {
apiWorld.getMaps().forEach(apiMap -> ((BlueMapMapImpl) apiMap).map().saveMarkerState());
}
}

0 comments on commit ad1f6f4

Please sign in to comment.