diff --git a/common/src/main/java/xaeroplus/XaeroPlus.java b/common/src/main/java/xaeroplus/XaeroPlus.java index c8ba6c0c..e840a230 100644 --- a/common/src/main/java/xaeroplus/XaeroPlus.java +++ b/common/src/main/java/xaeroplus/XaeroPlus.java @@ -4,7 +4,7 @@ import net.lenni0451.lambdaevents.generator.LambdaMetaFactoryGenerator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import xaero.common.platform.Services; +import xaero.map.platform.Services; import java.io.File; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/fabric/src/main/java/xaeroplus/fabric/XaeroPlusFabric.java b/fabric/src/main/java/xaeroplus/fabric/XaeroPlusFabric.java index fc8f4af8..33268cbf 100644 --- a/fabric/src/main/java/xaeroplus/fabric/XaeroPlusFabric.java +++ b/fabric/src/main/java/xaeroplus/fabric/XaeroPlusFabric.java @@ -12,7 +12,7 @@ import xaeroplus.XaeroPlus; import xaeroplus.fabric.util.FabricWaystonesHelperInit; import xaeroplus.fabric.util.compat.IncompatibleMinimapWarningScreen; -import xaeroplus.fabric.util.compat.MinimapBaseVersionCheck; +import xaeroplus.fabric.util.compat.XaeroPlusMinimapCompatibilityChecker; import xaeroplus.module.ModuleManager; import xaeroplus.settings.XaeroPlusSettingRegistry; import xaeroplus.settings.XaeroPlusSettingsReflectionHax; @@ -20,17 +20,25 @@ import java.util.List; +import static xaeroplus.fabric.util.compat.XaeroPlusMinimapCompatibilityChecker.versionCheckResult; + public class XaeroPlusFabric implements ClientModInitializer { public static void initialize() { if (XaeroPlus.initialized.compareAndSet(false, true)) { XaeroPlus.LOGGER.info("Initializing XaeroPlus"); - ModuleManager.init(); - boolean a = Globals.FOLLOW; // force static instances to init - XaeroPlusSettingRegistry.fastMapSetting.getValue(); // force static instances to init - List keybinds = XaeroPlusSettingsReflectionHax.keybindsSupplier.get(); - keybinds.forEach(KeyBindingHelper::registerKeyBinding); - FabricWaystonesHelperInit.doInit(); - } + if (!versionCheckResult.minimapCompatible()) { + XaeroPlus.LOGGER.error("Incompatible Xaero Minimap version detected! Expected: {} Actual: {}", + versionCheckResult.expectedVersion().getFriendlyString(), + versionCheckResult.anyPresentMinimapVersion().map(Version::getFriendlyString).orElse("None!")); + return; + } + ModuleManager.init(); + boolean a = Globals.FOLLOW; // force static instances to init + XaeroPlusSettingRegistry.fastMapSetting.getValue(); // force static instances to init + List keybinds = XaeroPlusSettingsReflectionHax.keybindsSupplier.get(); + keybinds.forEach(KeyBindingHelper::registerKeyBinding); + FabricWaystonesHelperInit.doInit(); + } } @Override @@ -38,11 +46,8 @@ public void onInitializeClient() { initialize(); ClientLifecycleEvents.CLIENT_STARTED.register(client -> { // needed as we can either accept Xaero's Minimap or BetterPVP but can't describe this in the fabric.mod.json - var versionCheckResult = MinimapBaseVersionCheck.versionCheck(); + var versionCheckResult = XaeroPlusMinimapCompatibilityChecker.versionCheckResult; if (versionCheckResult.minimapCompatible()) return; - XaeroPlus.LOGGER.error("Incompatible Xaero Minimap version detected! Expected: {} Actual: {}", - versionCheckResult.expectedVersion().getFriendlyString(), - versionCheckResult.anyPresentMinimapVersion().map(Version::getFriendlyString).orElse("None!")); var anyPresentVersion = versionCheckResult.minimapVersion().or(versionCheckResult::betterPvpVersion); Minecraft.getInstance().setScreen( new IncompatibleMinimapWarningScreen(anyPresentVersion, versionCheckResult.expectedVersion())); diff --git a/fabric/src/main/java/xaeroplus/fabric/util/compat/XaeroPlusCompatibleMinimapMixinPlugin.java b/fabric/src/main/java/xaeroplus/fabric/util/compat/XaeroPlusCompatibleMinimapMixinPlugin.java index 5c3bddc3..ff97cdfe 100644 --- a/fabric/src/main/java/xaeroplus/fabric/util/compat/XaeroPlusCompatibleMinimapMixinPlugin.java +++ b/fabric/src/main/java/xaeroplus/fabric/util/compat/XaeroPlusCompatibleMinimapMixinPlugin.java @@ -9,18 +9,18 @@ import java.util.List; import java.util.Set; +import static xaeroplus.fabric.util.compat.XaeroPlusMinimapCompatibilityChecker.versionCheckResult; + /** * Avoids applying XP mixins if Minimap is not present or not at a compatible version * * We want to either accept BetterPVP or Minimap at a specific version. But we can't make fabric.json enforce this so we have to do it ourselves */ public class XaeroPlusCompatibleMinimapMixinPlugin implements IMixinConfigPlugin { - private VersionCheckResult versionCheckResult; @Override public void onLoad(final String mixinPackage) { if (FabricLoader.getInstance().getEnvironmentType() != EnvType.CLIENT) return; - versionCheckResult = MinimapBaseVersionCheck.versionCheck(); } @Override diff --git a/fabric/src/main/java/xaeroplus/fabric/util/compat/MinimapBaseVersionCheck.java b/fabric/src/main/java/xaeroplus/fabric/util/compat/XaeroPlusMinimapCompatibilityChecker.java similarity index 69% rename from fabric/src/main/java/xaeroplus/fabric/util/compat/MinimapBaseVersionCheck.java rename to fabric/src/main/java/xaeroplus/fabric/util/compat/XaeroPlusMinimapCompatibilityChecker.java index 315befa6..8f3690cf 100644 --- a/fabric/src/main/java/xaeroplus/fabric/util/compat/MinimapBaseVersionCheck.java +++ b/fabric/src/main/java/xaeroplus/fabric/util/compat/XaeroPlusMinimapCompatibilityChecker.java @@ -8,20 +8,22 @@ import java.util.Optional; -public class MinimapBaseVersionCheck { +public class XaeroPlusMinimapCompatibilityChecker { - public static VersionCheckResult versionCheck() { + public static VersionCheckResult versionCheckResult = XaeroPlusMinimapCompatibilityChecker.versionCheck(); + + private static VersionCheckResult versionCheck() { try { - var compatibleMinimapVersion = SemanticVersion.parse(MinimapBaseVersionCheck.getCompatibleMinimapVersion()); - var minimapVersion = MinimapBaseVersionCheck.getVersion("xaerominimap"); - var betterPvpVersion = MinimapBaseVersionCheck.getVersion("xaerobetterpvp"); + var compatibleMinimapVersion = SemanticVersion.parse(XaeroPlusMinimapCompatibilityChecker.getCompatibleMinimapVersion()); + var minimapVersion = XaeroPlusMinimapCompatibilityChecker.getVersion("xaerominimap"); + var betterPvpVersion = XaeroPlusMinimapCompatibilityChecker.getVersion("xaerobetterpvp"); return new VersionCheckResult(minimapVersion, betterPvpVersion, compatibleMinimapVersion); } catch (VersionParsingException e) { throw new RuntimeException(e); } } - static Optional getVersion(final String modId) { + private static Optional getVersion(final String modId) { try { return FabricLoader.getInstance().getAllMods().stream() .filter(modContainer -> modContainer.getMetadata().getId().equals(modId)) @@ -40,7 +42,7 @@ static Optional getVersion(final String modId) { } } - static String getCompatibleMinimapVersion() { + private static String getCompatibleMinimapVersion() { return FabricLoader.getInstance().getModContainer("xaeroplus").get().getMetadata().getCustomValue("minimap_version").getAsString(); } }