Skip to content

Commit 27a9b19

Browse files
committed
Add file synchronization for json file
1 parent 70827a1 commit 27a9b19

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

SimpleAPI/src/main/java/com/bencodez/simpleapi/file/BungeeJsonFile.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,28 +169,28 @@ public JsonElement getNode(String path) {
169169
return null;
170170
}
171171

172-
public void setInt(String path, int value) {
172+
public synchronized void setInt(String path, int value) {
173173
JsonObject node = ensureParentObjectsExist(path);
174174
String lastPart = getLastPathPart(path);
175175
node.addProperty(lastPart, value);
176176
save();
177177
}
178178

179-
public void setString(String path, String value) {
179+
public synchronized void setString(String path, String value) {
180180
JsonObject node = ensureParentObjectsExist(path);
181181
String lastPart = getLastPathPart(path);
182182
node.addProperty(lastPart, value);
183183
save();
184184
}
185185

186-
public void setBoolean(String path, boolean value) {
186+
public synchronized void setBoolean(String path, boolean value) {
187187
JsonObject node = ensureParentObjectsExist(path);
188188
String lastPart = getLastPathPart(path);
189189
node.addProperty(lastPart, value);
190190
save();
191191
}
192192

193-
public void setLong(String path, long value) {
193+
public synchronized void setLong(String path, long value) {
194194
JsonObject node = ensureParentObjectsExist(path);
195195
if (node != null) {
196196
String lastPart = getLastPathPart(path);
@@ -199,7 +199,7 @@ public void setLong(String path, long value) {
199199
}
200200
}
201201

202-
public void setStringList(String path, List<String> value) {
202+
public synchronized void setStringList(String path, List<String> value) {
203203
JsonObject node = ensureParentObjectsExist(path);
204204
if (node != null) {
205205
String lastPart = getLastPathPart(path);
@@ -212,7 +212,7 @@ public void setStringList(String path, List<String> value) {
212212
}
213213
}
214214

215-
public void remove(String path) {
215+
public synchronized void remove(String path) {
216216
JsonObject node = navigateToNode(path);
217217
if (node != null) {
218218
String lastPart = getLastPathPart(path);
@@ -231,7 +231,7 @@ public void reload() {
231231
}
232232
}
233233

234-
public void save() {
234+
public synchronized void save() {
235235
try (FileWriter writer = new FileWriter(file)) {
236236
gson.toJson(conf, writer);
237237
} catch (IOException e) {

0 commit comments

Comments
 (0)