diff options
| author | Rime <81419447+Emirlol@users.noreply.github.com> | 2024-05-14 09:35:43 +0300 |
|---|---|---|
| committer | Rime <81419447+Emirlol@users.noreply.github.com> | 2024-05-23 13:31:48 +0300 |
| commit | e8d5f6f8380ad0baca3f43b26298e852643127b1 (patch) | |
| tree | ca52692da70220669741f7997b0f69309b21d65c /src/main/java/de/hysky/skyblocker/utils | |
| parent | eee4ee696a4c4263c7e00af54c6faac40fe93ed0 (diff) | |
| download | Skyblocker-e8d5f6f8380ad0baca3f43b26298e852643127b1.tar.gz Skyblocker-e8d5f6f8380ad0baca3f43b26298e852643127b1.tar.bz2 Skyblocker-e8d5f6f8380ad0baca3f43b26298e852643127b1.zip | |
Add SkyblockTime
Not sure if the AtomicReferences are helping with anything, just followed copilot.
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/utils')
| -rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/SkyblockTime.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/SkyblockTime.java b/src/main/java/de/hysky/skyblocker/utils/SkyblockTime.java new file mode 100644 index 00000000..36db4ef3 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/SkyblockTime.java @@ -0,0 +1,61 @@ +package de.hysky.skyblocker.utils; + +import de.hysky.skyblocker.utils.scheduler.Scheduler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; + +public class SkyblockTime { + private static final long SKYBLOCK_POCH = 1560275700000L; + public static final AtomicInteger skyblockYear = new AtomicInteger(0); + public static final AtomicReference<Season> skyblockSeason = new AtomicReference<>(Season.SPRING); + public static final AtomicReference<Month> skyblockMonth = new AtomicReference<>(Month.EARLY_SPRING); + public static final AtomicInteger skyblockDay = new AtomicInteger(0); + private static final Logger LOGGER = LoggerFactory.getLogger("Skyblocker Time"); + + private SkyblockTime() { + } + + public static void init() { + updateTime(); + //ScheduleCyclic already runs the task upon scheduling, so there's no need to call updateTime() here + Scheduler.INSTANCE.schedule(() -> Scheduler.INSTANCE.scheduleCyclic(SkyblockTime::updateTime, 1200 * 24), (int) (1200000 - (getSkyblockMillis() % 1200000)) / 50); + } + + private static long getSkyblockMillis() { + return System.currentTimeMillis() - SKYBLOCK_POCH; + } + + private static int getSkyblockYear() { + return (int) (Math.floor(getSkyblockMillis() / 446400000.0) + 1); + } + + private static int getSkyblockMonth() { + return (int) (Math.floor(getSkyblockMillis() / 37200000.0) % 12); + } + + private static int getSkyblockDay() { + return (int) (Math.floor(getSkyblockMillis() / 1200000.0) % 31 + 1); + } + + private static void updateTime() { + skyblockYear.set(getSkyblockYear()); + skyblockSeason.set(Season.values()[getSkyblockMonth() / 3]); + skyblockMonth.set(Month.values()[getSkyblockMonth()]); + skyblockDay.set(getSkyblockDay()); + LOGGER.info("[Skyblocker Time] Skyblock time updated to Year {}, Season {}, Month {}, Day {}",skyblockYear.get(), skyblockSeason.get(), skyblockMonth.get(), skyblockDay.get()); + } + + public enum Season { + SPRING, SUMMER, FALL, WINTER; + } + + public enum Month { + EARLY_SPRING, SPRING, LATE_SPRING, + EARLY_SUMMER, SUMMER, LATE_SUMMER, + EARLY_FALL, FALL, LATE_FALL, + EARLY_WINTER, WINTER, LATE_WINTER; + } +} |
