Data config no longer wiped on load.

Keys that no longer exist when it is time to save will be removed on
save as the remove operation keeps them in the data map with a null
value.
This commit is contained in:
extendedclip 2018-03-08 14:53:59 -05:00
parent e2ca19949e
commit 1e36114287
3 changed files with 11 additions and 22 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.extendedclip.papi.expansion.javascript</groupId>
<artifactId>javascript-expansion</artifactId>
<version>1.4.0-dev-1</version>
<version>1.4.0-dev-2</version>
<name>PAPI-Expansion-Javascript</name>
<description>PlaceholderAPI expansion for javascript placeholders</description>

View File

@ -117,28 +117,17 @@ public class JavascriptPlaceholder {
return false;
}
boolean save = false;
PlaceholderData data = new PlaceholderData();
for (String k : keys) {
keys.stream().forEach(k -> {
data.set(k, cfg.get(k));
cfg.set(k, null);
save = true;
}
});
if (!data.isEmpty()) {
this.setData(data);
return true;
}
if (save) {
try {
cfg.save(dataFile);
} catch (IOException e) {
e.printStackTrace();
}
}
return save;
return false;
}
public boolean saveData() {
@ -150,9 +139,9 @@ public class JavascriptPlaceholder {
return false;
}
for (Entry<String, Object> d : data.getData().entrySet()) {
cfg.set(d.getKey(), d.getValue());
}
data.getData().entrySet().forEach(e -> {
cfg.set(e.getKey(), e.getValue());
});
try {
cfg.save(dataFile);

View File

@ -23,15 +23,15 @@ public class PlaceholderData {
}
public boolean exists(String key) {
return map.containsKey(key);
return map.containsKey(key) && map.get(key) != null;
}
public Object get(String key) {
return map.get(key);
}
public boolean remove(String key) {
return map.remove(key) != null;
public void remove(String key) {
map.put(key, null);
}
public void set(String key, Object value) {