aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-08-24 00:30:33 +0200
committernea <nea@nea.moe>2023-08-24 00:30:33 +0200
commita271296fdc2ac139b3893adfd4f736985a8394a2 (patch)
tree465c6bf68c76750fd22a068e0a8b6ee865fe4150
parent32c6eeacb2a13d15fb2f3825b268c9ca32c4bf69 (diff)
downloadNotEnoughUpdates-a271296fdc2ac139b3893adfd4f736985a8394a2.tar.gz
NotEnoughUpdates-a271296fdc2ac139b3893adfd4f736985a8394a2.tar.bz2
NotEnoughUpdates-a271296fdc2ac139b3893adfd4f736985a8394a2.zip
Add custom calendar events
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java34
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java15
2 files changed, 49 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java
index 452187f3..f98523af 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/CalendarOverlay.java
@@ -28,6 +28,7 @@ import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe;
import io.github.moulberry.notenoughupdates.core.BackgroundBlur;
import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent;
import io.github.moulberry.notenoughupdates.util.ItemUtils;
+import io.github.moulberry.notenoughupdates.util.JsonUtils;
import io.github.moulberry.notenoughupdates.util.SkyBlockTime;
import io.github.moulberry.notenoughupdates.util.Utils;
import kotlin.Pair;
@@ -91,6 +92,7 @@ public class CalendarOverlay {
long rainInterval = 3600000L;
long thunderFrequency = 3;
long rainDuration = 1200 * 1000L;
+ List<Pair<Long, SBEvent>> externalEvents = new ArrayList<>();
public static void setEnabled(boolean enabled) {
CalendarOverlay.enabled = enabled;
@@ -264,6 +266,16 @@ public class CalendarOverlay {
fillRepeatingEvents(25 - eventMap.size());
fillSpecialMayors(4);
fillWeather();
+ fillRepoMandatedEvents();
+ }
+ }
+
+ public void fillRepoMandatedEvents() {
+ for (Pair<Long, SBEvent> externalEvent : externalEvents) {
+ addEvent(
+ SkyBlockTime.Companion.fromInstant(Instant.ofEpochMilli(externalEvent.component1())),
+ externalEvent.component2()
+ );
}
}
@@ -321,6 +333,28 @@ public class CalendarOverlay {
if (calendarJson.has("rainDuration")) {
rainDuration = calendarJson.get("rainDuration").getAsLong();
}
+ if (calendarJson.has("external")) {
+ List<Pair<Long, SBEvent>> externalEvents = new ArrayList<>();
+ for (JsonElement external : calendarJson.getAsJsonArray("external")) {
+ if (!(external instanceof JsonObject)) continue;
+ SBEvent sbEvent = new SBEvent(
+ Utils.getElementAsString(Utils.getElement(external, "id"), "external"),
+ Utils.getElementAsString(Utils.getElement(external, "display"), "§aExternal Event"),
+ Utils.getElementAsBool(Utils.getElement(external, "special"), false),
+ NotEnoughUpdates.INSTANCE.manager.createItem(Utils.getElementAsString(Utils.getElement(
+ external,
+ "itemStack"
+ ), "painting")),
+ JsonUtils.getJsonArrayOrEmpty((JsonObject) external, "description", it -> Utils.getElementAsString(it, "")),
+ Utils.getElementAsInt(Utils.getElement(external, "duration"), -1),
+ true
+ );
+ long start = Utils.getElementAsLong(Utils.getElement(external, "start"), 0);
+ externalEvents.add(new Pair<>(start, sbEvent));
+ }
+ this.externalEvents = externalEvents;
+ }
+ eventMap.clear();
}
@SubscribeEvent
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) {