fix: make jsonObject in PersistentDataUtilities synchronous (hopefully)
This commit is contained in:
parent
06522fadcc
commit
60a1d069c7
5 changed files with 24 additions and 16 deletions
|
@ -25,8 +25,8 @@ public class FilterPlugin extends PlayersPlugin.Listener {
|
|||
private final Gson gson = new Gson();
|
||||
|
||||
static {
|
||||
if (PersistentDataUtilities.jsonObject.has("filters")) {
|
||||
filteredPlayers = PersistentDataUtilities.jsonObject.get("filters").getAsJsonArray();
|
||||
if (PersistentDataUtilities.has("filters")) {
|
||||
filteredPlayers = PersistentDataUtilities.get("filters").getAsJsonArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ public class IPFilterPlugin extends PlayersPlugin.Listener {
|
|||
public static JsonArray filteredIPs = new JsonArray();
|
||||
|
||||
static {
|
||||
if (PersistentDataUtilities.jsonObject.has("ipFilters")) {
|
||||
filteredIPs = PersistentDataUtilities.jsonObject.get("ipFilters").getAsJsonArray();
|
||||
if (PersistentDataUtilities.has("ipFilters")) {
|
||||
filteredIPs = PersistentDataUtilities.get("ipFilters").getAsJsonArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ public class MailPlugin extends PlayersPlugin.Listener {
|
|||
private final Gson gson = new Gson();
|
||||
|
||||
static {
|
||||
if (PersistentDataUtilities.jsonObject.has("mails")) {
|
||||
mails = PersistentDataUtilities.jsonObject.get("mails").getAsJsonArray();
|
||||
if (PersistentDataUtilities.has("mails")) {
|
||||
mails = PersistentDataUtilities.get("mails").getAsJsonArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ public class PlayersPersistentDataPlugin extends PlayersPlugin.Listener {
|
|||
public static JsonObject playersObject = new JsonObject();
|
||||
|
||||
static {
|
||||
if (PersistentDataUtilities.jsonObject.has("players")) {
|
||||
playersObject = PersistentDataUtilities.jsonObject.get("players").getAsJsonObject();
|
||||
if (PersistentDataUtilities.has("players")) {
|
||||
playersObject = PersistentDataUtilities.get("players").getAsJsonObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public class PersistentDataUtilities {
|
|||
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
public static JsonObject jsonObject = new JsonObject();
|
||||
private static JsonObject jsonObject = new JsonObject();
|
||||
|
||||
private static final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class PersistentDataUtilities {
|
|||
}
|
||||
}
|
||||
|
||||
private static void writeToFile() {
|
||||
private static synchronized void writeToFile() {
|
||||
if (stopping) return;
|
||||
|
||||
lock.lock();
|
||||
|
@ -56,7 +56,7 @@ public class PersistentDataUtilities {
|
|||
}
|
||||
}
|
||||
|
||||
public static void stop () {
|
||||
public static synchronized void stop () {
|
||||
stopping = true;
|
||||
|
||||
lock.lock();
|
||||
|
@ -68,7 +68,15 @@ public class PersistentDataUtilities {
|
|||
}
|
||||
}
|
||||
|
||||
public static void put (String property, JsonElement value) {
|
||||
public static synchronized boolean has (String property) {
|
||||
return jsonObject.has(property);
|
||||
}
|
||||
|
||||
public static synchronized JsonElement get (String property) {
|
||||
return jsonObject.get(property);
|
||||
}
|
||||
|
||||
public static synchronized void put (String property, JsonElement value) {
|
||||
lock.lock();
|
||||
|
||||
try {
|
||||
|
@ -79,19 +87,19 @@ public class PersistentDataUtilities {
|
|||
}
|
||||
}
|
||||
|
||||
public static void put (String property, String value) {
|
||||
public static synchronized void put (String property, String value) {
|
||||
put(property, new JsonPrimitive(value));
|
||||
}
|
||||
|
||||
public static void put (String property, boolean value) {
|
||||
public static synchronized void put (String property, boolean value) {
|
||||
put(property, new JsonPrimitive(value));
|
||||
}
|
||||
|
||||
public static void put (String property, int value) {
|
||||
public static synchronized void put (String property, int value) {
|
||||
put(property, new JsonPrimitive(value));
|
||||
}
|
||||
|
||||
public static void put (String property, char value) {
|
||||
public static synchronized void put (String property, char value) {
|
||||
put(property, new JsonPrimitive(value));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue