mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-25 12:05:13 +01:00
Fix syncronization issue with the marker-api
This commit is contained in:
parent
c31945444d
commit
470a5cbad1
@ -92,63 +92,67 @@ public synchronized void load() throws IOException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void load(boolean overwriteChanges) throws IOException {
|
private synchronized void load(boolean overwriteChanges) throws IOException {
|
||||||
Set<String> externallyRemovedSets = new HashSet<>(markerSets.keySet());
|
synchronized (MarkerAPIImpl.class) {
|
||||||
|
Set<String> externallyRemovedSets = new HashSet<>(markerSets.keySet());
|
||||||
|
|
||||||
if (markerFile.exists() && markerFile.isFile()) {
|
if (markerFile.exists() && markerFile.isFile()) {
|
||||||
GsonConfigurationLoader loader = GsonConfigurationLoader.builder().file(markerFile).build();
|
GsonConfigurationLoader loader = GsonConfigurationLoader.builder().file(markerFile).build();
|
||||||
ConfigurationNode node = loader.load();
|
ConfigurationNode node = loader.load();
|
||||||
|
|
||||||
for (ConfigurationNode markerSetNode : node.node("markerSets").childrenList()) {
|
for (ConfigurationNode markerSetNode : node.node("markerSets").childrenList()) {
|
||||||
String setId = markerSetNode.node("id").getString();
|
String setId = markerSetNode.node("id").getString();
|
||||||
if (setId == null) {
|
if (setId == null) {
|
||||||
Logger.global.logDebug("Marker-API: Failed to load a markerset: No id defined!");
|
Logger.global.logDebug("Marker-API: Failed to load a markerset: No id defined!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
externallyRemovedSets.remove(setId);
|
externallyRemovedSets.remove(setId);
|
||||||
if (!overwriteChanges && removedMarkerSets.contains(setId)) continue;
|
if (!overwriteChanges && removedMarkerSets.contains(setId)) continue;
|
||||||
|
|
||||||
MarkerSetImpl set = markerSets.get(setId);
|
MarkerSetImpl set = markerSets.get(setId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (set == null) {
|
if (set == null) {
|
||||||
set = new MarkerSetImpl(setId);
|
set = new MarkerSetImpl(setId);
|
||||||
set.load(api, markerSetNode, true);
|
set.load(api, markerSetNode, true);
|
||||||
} else {
|
} else {
|
||||||
set.load(api, markerSetNode, overwriteChanges);
|
set.load(api, markerSetNode, overwriteChanges);
|
||||||
|
}
|
||||||
|
markerSets.put(setId, set);
|
||||||
|
} catch (MarkerFileFormatException ex) {
|
||||||
|
Logger.global.logDebug("Marker-API: Failed to load marker-set '" + setId + ": " + ex);
|
||||||
}
|
}
|
||||||
markerSets.put(setId, set);
|
|
||||||
} catch (MarkerFileFormatException ex) {
|
|
||||||
Logger.global.logDebug("Marker-API: Failed to load marker-set '" + setId + ": " + ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (overwriteChanges) {
|
||||||
if (overwriteChanges) {
|
for (String setId : externallyRemovedSets) {
|
||||||
for (String setId : externallyRemovedSets) {
|
markerSets.remove(setId);
|
||||||
markerSets.remove(setId);
|
}
|
||||||
|
|
||||||
|
removedMarkerSets.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
removedMarkerSets.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void save() throws IOException {
|
public synchronized void save() throws IOException {
|
||||||
load(false);
|
synchronized (MarkerAPIImpl.class) {
|
||||||
|
load(false);
|
||||||
|
|
||||||
FileUtils.createFile(markerFile);
|
FileUtils.createFile(markerFile);
|
||||||
|
|
||||||
GsonConfigurationLoader loader = GsonConfigurationLoader.builder().file(markerFile).build();
|
GsonConfigurationLoader loader = GsonConfigurationLoader.builder().file(markerFile).build();
|
||||||
ConfigurationNode node = loader.createNode();
|
ConfigurationNode node = loader.createNode();
|
||||||
|
|
||||||
for (MarkerSetImpl set : markerSets.values()) {
|
for (MarkerSetImpl set : markerSets.values()) {
|
||||||
set.save(node.node("markerSets").appendListNode());
|
set.save(node.node("markerSets").appendListNode());
|
||||||
|
}
|
||||||
|
|
||||||
|
loader.save(node);
|
||||||
|
|
||||||
|
removedMarkerSets.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
loader.save(node);
|
|
||||||
|
|
||||||
removedMarkerSets.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user