diff options
| author | Moulberry <james.jenour@student.scotch.wa.edu.au> | 2020-07-20 05:12:05 +1000 |
|---|---|---|
| committer | Moulberry <james.jenour@student.scotch.wa.edu.au> | 2020-07-20 05:12:05 +1000 |
| commit | 8499a98beeb556c16987fc375dbd7d05d6c27ab4 (patch) | |
| tree | afd17c1abac0eb147258f8f12d33a9ee7bd21fd8 /src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java | |
| parent | f7d3491def0f7498d7bf0d547445f75f0c515912 (diff) | |
| download | notenoughupdates-8499a98beeb556c16987fc375dbd7d05d6c27ab4.tar.gz notenoughupdates-8499a98beeb556c16987fc375dbd7d05d6c27ab4.tar.bz2 notenoughupdates-8499a98beeb556c16987fc375dbd7d05d6c27ab4.zip | |
some profile viewer stuffs
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.java | 48 |
1 files changed, 48 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 57b89a0a..66400c00 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -1,5 +1,9 @@ package io.github.moulberry.notenoughupdates.util; +import com.google.common.base.Splitter; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; import com.mojang.authlib.Agent; import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; import com.mojang.authlib.yggdrasil.YggdrasilUserAuthentication; @@ -376,6 +380,50 @@ public class Utils { drawHoveringText(textLines, mouseX, mouseY, screenWidth, screenHeight, maxTextWidth, font, true); } + public static JsonObject getConstant(String constant) { + File repo = NotEnoughUpdates.INSTANCE.manager.repoLocation; + if(repo.exists()) { + File jsonFile = new File(repo, "constants/"+constant+".json"); + try { + return NotEnoughUpdates.INSTANCE.manager.getJsonFromFile(jsonFile); + } catch (Exception ignored) { + } + } + System.out.println(constant + " = null"); + return null; + } + + public static float getElementAsFloat(JsonElement element, float def) { + if(element == null) return def; + if(!element.isJsonPrimitive()) return def; + JsonPrimitive prim = element.getAsJsonPrimitive(); + if(!prim.isNumber()) return def; + return prim.getAsFloat(); + } + + public static String getElementAsString(JsonElement element, String def) { + if(element == null) return def; + if(!element.isJsonPrimitive()) return def; + JsonPrimitive prim = element.getAsJsonPrimitive(); + if(!prim.isString()) return def; + return prim.getAsString(); + } + + public static Splitter PATH_SPLITTER = Splitter.on(".").omitEmptyStrings().limit(2); + public static JsonElement getElement(JsonElement element, String path) { + List<String> path_split = PATH_SPLITTER.splitToList(path); + if(element instanceof JsonObject) { + JsonElement e = element.getAsJsonObject().get(path_split.get(0)); + if(path_split.size() > 1) { + return getElement(e, path_split.get(1)); + } else { + return e; + } + } else { + return element; + } + } + public static ChatStyle createClickStyle(ClickEvent.Action action, String value) { ChatStyle style = new ChatStyle(); style.setChatClickEvent(new ClickEvent(action, value)); |
