diff options
| author | Roman / Linnea Gräf <roman.graef@gmail.com> | 2022-09-01 17:15:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-01 17:15:51 +0200 |
| commit | 43aa4ae5059012171372cb182c46bf95905e811e (patch) | |
| tree | 73709c1472e21981efadd00c73f30936cee0ef97 /src/main/java/io/github/moulberry/notenoughupdates/envcheck/EnvironmentScan.java | |
| parent | ce85f467928e085d4756c04cdf60b6a330b756e3 (diff) | |
| download | notenoughupdates-43aa4ae5059012171372cb182c46bf95905e811e.tar.gz notenoughupdates-43aa4ae5059012171372cb182c46bf95905e811e.tar.bz2 notenoughupdates-43aa4ae5059012171372cb182c46bf95905e811e.zip | |
Warn on invalid forge configs (and crash on 1.19 cause java is a bitch and i dont want to write a custom tweaker to load jar in jars, even tho i totally could, it would just not be very practical) (#236)
* warning
* Also warn on fabric
* also work on forge
* Fix grammar issue
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/envcheck/EnvironmentScan.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/envcheck/EnvironmentScan.java | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/envcheck/EnvironmentScan.java b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/EnvironmentScan.java new file mode 100644 index 00000000..8e0f24b9 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/EnvironmentScan.java @@ -0,0 +1,85 @@ +package io.github.moulberry.notenoughupdates.envcheck; + +import javax.swing.*; +import java.lang.reflect.Field; +import java.util.Objects; + +public class EnvironmentScan { + + static Class<?> tryGetClass(String name) { + try { + return Class.forName(name); + } catch (ClassNotFoundException e) { + return null; + } + } + + static Object tryGetField(Class<?> clazz, Object inst, String name) { + if (clazz == null) return null; + try { + Field declaredField = clazz.getDeclaredField(name); + return declaredField.get(inst); + } catch (NoSuchFieldException | IllegalAccessException ignored) { + } + return null; + } + + + static boolean isAtLeast(Object left, int right) { + if (left instanceof Integer) { + return (Integer) left >= right; + } + return false; + } + + static boolean shouldCheckOnce = true; + + static void checkEnvironmentOnce() { + if (shouldCheckOnce) checkEnvironment(); + } + + + static void checkEnvironment() { + shouldCheckOnce = false; + checkForgeEnvironment(); + } + + static void checkForgeEnvironment() { + Class<?> forgeVersion = tryGetClass("net.minecraftforge.common.ForgeVersion"); + if (forgeVersion == null + || !Objects.equals(tryGetField(forgeVersion, null, "majorVersion"), 11) + || !Objects.equals(tryGetField(forgeVersion, null, "minorVersion"), 15) + || !isAtLeast(tryGetField(forgeVersion, null, "revisionVersion"), 1) + || !Objects.equals(tryGetField(forgeVersion, null, "mcVersion"), "1.8.9") + ) { + + System.out.printf("Forge Version : %s%nMajor : %s%nMinor : %s%nRevision : %s%nMinecraft : %s%n", + forgeVersion, + tryGetField(forgeVersion, null, "majorVersion"), + tryGetField(forgeVersion, null, "minorVersion"), + tryGetField(forgeVersion, null, "revisionVersion"), + tryGetField(forgeVersion, null, "mcVersion") + ); + missingOrOutdatedForgeError(); + } + } + + static void missingOrOutdatedForgeError() { + showErrorMessage( + "You just launched NotEnoughUpdates with the wrong (or no) modloader installed.", + "", + "NotEnoughUpdates only works in Minecraft 1.8.9, with Forge 11.15.1+", + "Please relaunch NotEnoughUpdates in the correct environment.", + "If you are using Minecraft 1.8.9 with Forge 11.15.1+ installed, please contact support.", + "Click OK to launch anyways." + ); + } + + + public static void showErrorMessage(String... messages) { + String message = String.join("\n", messages); + JOptionPane.showMessageDialog( + null, message, "NotEnoughUpdates - Problematic System Configuration", JOptionPane.ERROR_MESSAGE + ); + } +} |
