Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public abstract class AbstractDataTask extends Task {

protected final World world;
protected final Map<String, Long> lastUpdated = new HashMap<>();
protected final Map<String, Long> lastHashCode = new HashMap<>();
protected final ExecutorService executor;
protected final String executorName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,31 @@ public void parse() {

long now = System.currentTimeMillis();
long lastUpdated = this.lastUpdated.getOrDefault(key, 0L);
long lastHashCode = this.lastHashCode.getOrDefault(key, 0L);

if (now - lastUpdated > Math.max(TickUtil.toMilliseconds(layer.getUpdateInterval()), 1000)) {
List<Marker<?>> list = new ArrayList<>(layer.getMarkers());
FileUtil.writeJson(this.gson.toJson(list), this.world.getMarkersDirectory().resolve(key.replace(":", "-") + ".json"));
String jsonMarkers = this.gson.toJson(list);
long hashCode = jsonMarkers.hashCode();
if (lastHashCode != hashCode)
{
FileUtil.writeJson(jsonMarkers, this.world.getMarkersDirectory().resolve(key.replace(":", "-") + ".json"));
}
this.lastHashCode.put(key, hashCode);
this.lastUpdated.put(key, now);
}
} catch (Throwable t) {
Logger.severe("Failed to process layer " + key + " for world " + world.getName(), t);
}
});

FileUtil.writeJson(this.gson.toJson(layers), this.world.getTilesDirectory().resolve("markers.json"));
long lastHashCode = this.lastHashCode.getOrDefault("", 0L);
String markersJson = this.gson.toJson(layers);
long hashCode = markersJson.hashCode();
if (lastHashCode != hashCode)
{
FileUtil.writeJson(this.gson.toJson(layers), this.world.getTilesDirectory().resolve("markers.json"));
this.lastHashCode.put("", hashCode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import net.pl3x.map.core.Pl3xMap;
Expand All @@ -46,14 +47,14 @@

@NullMarked
public class UpdateSettingsData extends Task {
private int fileTick;
private final Gson gson = new GsonBuilder()
//.setPrettyPrinting()
.disableHtmlEscaping()
.serializeNulls()
.setLenient()
.create();
private int jsonHashCache = -1;

private HashMap<String, Long> jsonHashCache = new HashMap<>();
private final ExecutorService executor;

private CompletableFuture<Void> future;
Expand Down Expand Up @@ -126,7 +127,15 @@ private List<Map<String, Object>> parseWorlds() {
settings.put("zoom", zoom);
settings.put("ui", ui);

FileUtil.writeJson(this.gson.toJson(settings), world.getTilesDirectory().resolve("settings.json"));
String key = world.getName();
long lastHashCode = this.jsonHashCache.getOrDefault(key, 0L);
String worldSettingsJson = this.gson.toJson(settings);
long hashCode = worldSettingsJson.hashCode();
if (lastHashCode != hashCode)
{
FileUtil.writeJson(worldSettingsJson, world.getTilesDirectory().resolve("settings.json"));
this.jsonHashCache.put(key, hashCode);
}

List<Object> renderers = new ArrayList<>();
world.getRenderers().forEach((rendererKey, builder) -> {
Expand Down Expand Up @@ -185,15 +194,12 @@ private void parseSettings() {
}

String json = this.gson.toJson(map);

if (jsonHashCache != json.hashCode()) {
long lastHashCode = this.jsonHashCache.getOrDefault("", 0L);
long hashCode = json.hashCode();
if (lastHashCode != hashCode) {
Pl3xMap.api().getHttpdServer().getLiveDataHandler().send("settings", json);
jsonHashCache = json.hashCode();
}

if (fileTick++ >= 20) {
fileTick = 0;
FileUtil.writeJson(json, FileUtil.getTilesDir().resolve("settings.json"));
this.jsonHashCache.put("", hashCode);
}
}
}