From 6f25e8bf8f24bcbf5575888492e0a557e5d01deb Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Wed, 30 Aug 2023 18:44:03 +0200 Subject: Add repo updateable rain timers (#813) * Add repo updateable rain timers * Add custom calendar events --------- Co-authored-by: nopo --- .../io/github/moulberry/notenoughupdates/util/Utils.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 052ea33f..847b9430 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -1571,6 +1571,13 @@ public class Utils { if (!prim.isNumber()) return def; return prim.getAsInt(); } + public static long getElementAsLong(JsonElement element, long def) { + if (element == null) return def; + if (!element.isJsonPrimitive()) return def; + JsonPrimitive prim = element.getAsJsonPrimitive(); + if (!prim.isNumber()) return def; + return prim.getAsLong(); + } public static String getElementAsString(JsonElement element, String def) { if (element == null) return def; @@ -1580,6 +1587,14 @@ public class Utils { return prim.getAsString(); } + public static boolean getElementAsBool(JsonElement element, boolean def) { + if (element == null) return def; + if (!element.isJsonPrimitive()) return def; + JsonPrimitive prim = element.getAsJsonPrimitive(); + if (!prim.isBoolean()) return def; + return prim.getAsBoolean(); + } + public static JsonElement getElement(JsonElement element, String path) { List path_split = PATH_SPLITTER.splitToList(path); if (element instanceof JsonObject) { -- cgit