From bee4d2e9f72638f8cfa16cab5c2d54ca821280fe Mon Sep 17 00:00:00 2001 From: Owen Stubbs Date: Fri, 19 May 2023 20:52:06 +0100 Subject: [PATCH] 4.0.2 --- gradle.properties | 6 +- .../java/net/emc/emce/EarthMCEssentials.java | 1 - .../net/emc/emce/modules/EventRegistry.java | 61 +++++++++++-------- .../net/emc/emce/modules/TaskScheduler.java | 22 ++++--- src/main/resources/fabric.mod.json | 4 +- 5 files changed, 54 insertions(+), 40 deletions(-) diff --git a/gradle.properties b/gradle.properties index eb6659c..103739b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,15 +7,15 @@ org.gradle.workers.max=4 minecraft_version=1.19.4 yarn_mappings=1.19.4+build.2 loader_version=0.14.19 -fabric_version=0.78.0+1.19.4 +fabric_version=0.81.0+1.19.4 # Mod Properties name = EarthMCEssentials -mod_version = 4.0.1 +mod_version = 4.0.2 maven_group = net.emc.emce # Library versions cloth_config_version=10.0.96 -mod_menu_version=6.1.0-rc.4 +mod_menu_version=6.2.2 adventure_fabric_version=5.8.0 wrapper_version=0.10.2 \ No newline at end of file diff --git a/src/main/java/net/emc/emce/EarthMCEssentials.java b/src/main/java/net/emc/emce/EarthMCEssentials.java index c9a24e4..f6aad0a 100644 --- a/src/main/java/net/emc/emce/EarthMCEssentials.java +++ b/src/main/java/net/emc/emce/EarthMCEssentials.java @@ -43,7 +43,6 @@ public class EarthMCEssentials implements ModInitializer { private final TaskScheduler scheduler = new TaskScheduler(); public String mapName = "aurora"; - public int sessionCounter = 0; public static KeyBinding configKeybinding; private ModConfig config = null; diff --git a/src/main/java/net/emc/emce/modules/EventRegistry.java b/src/main/java/net/emc/emce/modules/EventRegistry.java index a3f5129..bcced71 100644 --- a/src/main/java/net/emc/emce/modules/EventRegistry.java +++ b/src/main/java/net/emc/emce/modules/EventRegistry.java @@ -14,8 +14,14 @@ import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; import net.minecraft.client.gui.screen.Screen; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import static net.emc.emce.EarthMCEssentials.instance; +import static net.emc.emce.utils.EarthMCAPI.clientOnline; import static net.emc.emce.utils.EarthMCAPI.fetchEndpoints; import static net.emc.emce.utils.ModUtils.isConnectedToEMC; import static net.emc.emce.utils.ModUtils.updateServerName; @@ -56,51 +62,54 @@ public static void RegisterHud() { OverlayRenderer.Render(matrixStack)); } + static ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1); public static void RegisterConnection(EarthMCEssentials instance) { ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { - System.out.println("EMCE > New game session detected."); - updateServerName(); - OverlayRenderer.Init(); - instance.setShouldRender(instance.config().general.enableMod); - instance.setDebugEnabled(instance.config().general.debugLog); + // Allow 3 seconds for Dynmap to update. + exec.schedule(() -> { + //region Detect client map (if on emc) + String curMap = getClientMap(); + if (curMap == null) return; // Don't do anything if not on EMC. - if (instance.sessionCounter == 1) { - RegisterScreen(); - RegisterHud(); - } + System.out.println("EMCE > New game session detected."); + //endregion + + //region Run regardless of map + instance.setShouldRender(instance.config().general.enableMod); + instance.setDebugEnabled(instance.config().general.debugLog); - if (isConnectedToEMC()) { - updateSessionCounter('+'); fetchEndpoints(); + OverlayRenderer.Init(); - // Out of queue, begin map check. - if (instance.sessionCounter > 1) - instance.scheduler().initMap(); - } + RegisterScreen(); + RegisterHud(); + //endregion + if (!inQueue(curMap)) instance.scheduler().initMap(); + else instance.scheduler().reset(); + }, 3, TimeUnit.SECONDS); }); ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> { System.out.println("EMCE > Disconnected."); ModUtils.setServerName(""); - OverlayRenderer.Clear(); - - instance().sessionCounter = 0; - instance().scheduler().setHasMap(null); + instance().scheduler().reset(); }); } - private static void updateSessionCounter(char type) { - int oldCount = instance().sessionCounter; + private static @Nullable String getClientMap() { + if (!isConnectedToEMC()) return null; + + if (clientOnline("aurora")) return "aurora"; + if (clientOnline("nova")) return "nova"; - if (type == '+') instance().sessionCounter++; - else instance().sessionCounter--; + return "queue"; + } - String debugStr = "Updated session counter from " + oldCount + " to " + instance().sessionCounter; - Messaging.sendDebugMessage(debugStr); - System.out.println("EMCE > " + debugStr); + private static boolean inQueue(String map) { + return Objects.equals(map, "queue"); } } \ No newline at end of file diff --git a/src/main/java/net/emc/emce/modules/TaskScheduler.java b/src/main/java/net/emc/emce/modules/TaskScheduler.java index eced20d..807e410 100644 --- a/src/main/java/net/emc/emce/modules/TaskScheduler.java +++ b/src/main/java/net/emc/emce/modules/TaskScheduler.java @@ -12,7 +12,6 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import static io.github.emcw.utils.GsonUtil.serialize; import static net.emc.emce.EarthMCEssentials.instance; import static net.emc.emce.utils.EarthMCAPI.clientOnline; @@ -46,14 +45,21 @@ public void stop() { } public void initMap() { - service = Executors.newScheduledThreadPool(4); - service.scheduleAtFixedRate(() -> { - if (hasMap) return; + service = Executors.newScheduledThreadPool(2); + service.scheduleAtFixedRate(this::checkMap, 0, 10, TimeUnit.SECONDS); + } + + void checkMap() { + if (hasMap) return; + + if (clientOnline("aurora")) setHasMap("aurora"); + else if (clientOnline("nova")) setHasMap("nova"); + else setHasMap(null); + } - if (clientOnline("aurora")) setHasMap("aurora"); - else if (clientOnline("nova")) setHasMap("nova"); - else setHasMap(null); - }, 5, 15, TimeUnit.SECONDS); + public void reset() { + OverlayRenderer.Clear(); + setHasMap(null); } public void setHasMap(String map) { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b50d42c..480112b 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,8 +27,8 @@ "emce.mixins.json" ], "depends": { - "fabricloader": ">=0.14.12", - "fabric-api": ">=0.76.0", + "fabricloader": ">=0.14.15", + "fabric-api": ">=0.78.0", "minecraft": ">=1.19.3", "java": ">=17" },