refactor: getOrDefault in PersistentDataUtilities
This commit is contained in:
@@ -1 +1 @@
|
||||
1145
|
||||
1147
|
||||
@@ -20,16 +20,10 @@ import java.util.regex.Pattern;
|
||||
public class FilterPlugin extends PlayersPlugin.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
public static JsonArray filteredPlayers = new JsonArray();
|
||||
public static JsonArray filteredPlayers = PersistentDataUtilities.getOrDefault("filters", new JsonArray()).getAsJsonArray();
|
||||
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
static {
|
||||
if (PersistentDataUtilities.has("filters")) {
|
||||
filteredPlayers = PersistentDataUtilities.get("filters").getAsJsonArray();
|
||||
}
|
||||
}
|
||||
|
||||
public FilterPlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
|
||||
@@ -12,13 +12,7 @@ import java.util.concurrent.TimeUnit;
|
||||
public class IPFilterPlugin extends PlayersPlugin.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
public static JsonArray filteredIPs = new JsonArray();
|
||||
|
||||
static {
|
||||
if (PersistentDataUtilities.has("ipFilters")) {
|
||||
filteredIPs = PersistentDataUtilities.get("ipFilters").getAsJsonArray();
|
||||
}
|
||||
}
|
||||
public static JsonArray filteredIPs = PersistentDataUtilities.getOrDefault("ipFilters", new JsonArray()).getAsJsonArray();
|
||||
|
||||
public IPFilterPlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
@@ -14,16 +14,10 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||
public class MailPlugin extends PlayersPlugin.Listener {
|
||||
private final Bot bot;
|
||||
|
||||
public static JsonArray mails = new JsonArray();
|
||||
public static JsonArray mails = PersistentDataUtilities.getOrDefault("mails", new JsonArray()).getAsJsonArray();
|
||||
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
static {
|
||||
if (PersistentDataUtilities.has("mails")) {
|
||||
mails = PersistentDataUtilities.get("mails").getAsJsonArray();
|
||||
}
|
||||
}
|
||||
|
||||
public MailPlugin (Bot bot) {
|
||||
this.bot = bot;
|
||||
|
||||
|
||||
@@ -11,13 +11,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PlayersPersistentDataPlugin extends PlayersPlugin.Listener {
|
||||
public static JsonObject playersObject = new JsonObject();
|
||||
|
||||
static {
|
||||
if (PersistentDataUtilities.has("players")) {
|
||||
playersObject = PersistentDataUtilities.get("players").getAsJsonObject();
|
||||
}
|
||||
}
|
||||
public static JsonObject playersObject = PersistentDataUtilities.getOrDefault("players", new JsonObject()).getAsJsonObject();
|
||||
|
||||
private final Bot bot;
|
||||
|
||||
|
||||
@@ -77,6 +77,10 @@ public class PersistentDataUtilities {
|
||||
return jsonObject.get(property);
|
||||
}
|
||||
|
||||
public static synchronized JsonElement getOrDefault (String property, JsonElement defaultElement) {
|
||||
return has(property) ? get(property) : defaultElement;
|
||||
}
|
||||
|
||||
public static synchronized void put (String property, JsonElement value) {
|
||||
lock.lock();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user