aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
diff options
context:
space:
mode:
authorLinnea Gräf <roman.graef@gmail.com>2023-08-30 18:44:03 +0200
committerGitHub <noreply@github.com>2023-08-30 18:44:03 +0200
commit6f25e8bf8f24bcbf5575888492e0a557e5d01deb (patch)
treedcb44d4f5e8a1e076011bb54d423bfe2f14cd34b /src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java
parent2f768fbe0e87debd50ac2ea6d929fa6867a73c0f (diff)
downloadnotenoughupdates-6f25e8bf8f24bcbf5575888492e0a557e5d01deb.tar.gz
notenoughupdates-6f25e8bf8f24bcbf5575888492e0a557e5d01deb.tar.bz2
notenoughupdates-6f25e8bf8f24bcbf5575888492e0a557e5d01deb.zip
Add repo updateable rain timers (#813)
* Add repo updateable rain timers * Add custom calendar events --------- Co-authored-by: nopo <nopotheemail@gmail.com>
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java15
1 files changed, 15 insertions, 0 deletions
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<String> path_split = PATH_SPLITTER.splitToList(path);
if (element instanceof JsonObject) {