Skip to content

Commit

Permalink
4.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen3H committed May 19, 2023
1 parent d1a5ee9 commit bee4d2e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 40 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion src/main/java/net/emc/emce/EarthMCEssentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
61 changes: 35 additions & 26 deletions src/main/java/net/emc/emce/modules/EventRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
22 changes: 14 additions & 8 deletions src/main/java/net/emc/emce/modules/TaskScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit bee4d2e

Please sign in to comment.