aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-08-05 10:22:21 +0200
committernea <romangraef@gmail.com>2022-08-19 21:54:59 +0200
commitdab56f480e05c71d1317c4df8d3b36aa12112db2 (patch)
treee36888a8a24d6657c25ab22df8f0235e3a4b80e1 /src
parentb2d35428ac089ac104a2ea8212d8332c27a6cbee (diff)
downloadNotEnoughUpdates-dab56f480e05c71d1317c4df8d3b36aa12112db2.tar.gz
NotEnoughUpdates-dab56f480e05c71d1317c4df8d3b36aa12112db2.tar.bz2
NotEnoughUpdates-dab56f480e05c71d1317c4df8d3b36aa12112db2.zip
warning
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/envcheck/EnvironmentScan.java85
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java46
-rw-r--r--src/main/resources/META-INF/mods.toml14
-rw-r--r--src/main/resources/META-INF/versions/9/module-info.classbin0 -> 211 bytes
-rw-r--r--src/main/resources/mixins.notenoughupdates.json1
5 files changed, 146 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..a42b4cb6
--- /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 in 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
+ );
+ }
+}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java
new file mode 100644
index 00000000..44e24ff4
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java
@@ -0,0 +1,46 @@
+package io.github.moulberry.notenoughupdates.envcheck;
+
+import org.spongepowered.asm.lib.tree.ClassNode;
+import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
+import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
+
+import java.util.List;
+import java.util.Set;
+
+public class NEUMixinConfigPlugin implements IMixinConfigPlugin {
+
+ static {
+ EnvironmentScan.checkEnvironmentOnce();
+ }
+
+ @Override
+ public void onLoad(String mixinPackage) {
+ }
+
+ @Override
+ public String getRefMapperConfig() {
+ return null;
+ }
+
+ @Override
+ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
+ return true;
+ }
+
+ @Override
+ public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
+ }
+
+ @Override
+ public List<String> getMixins() {
+ return null;
+ }
+
+ @Override
+ public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
+ }
+
+ @Override
+ public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
+ }
+}
diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml
new file mode 100644
index 00000000..281faf65
--- /dev/null
+++ b/src/main/resources/META-INF/mods.toml
@@ -0,0 +1,14 @@
+# This mods.toml is loaded by forge 1.13-1.19 and is only here to make forge display an error message
+modLoader = "javafml"
+loaderVersion = "[12,)"
+license = "LGPL"
+
+[[mods]]
+modId="notenoughupdateserrordisplay"
+version="99.99"
+displayName="NotEnoughUpdates (1.8.9)"
+description='''
+This mod description is only here to warn you about using the wrong version of Minecraft and Forge.
+'''
+
+
diff --git a/src/main/resources/META-INF/versions/9/module-info.class b/src/main/resources/META-INF/versions/9/module-info.class
new file mode 100644
index 00000000..6438019f
--- /dev/null
+++ b/src/main/resources/META-INF/versions/9/module-info.class
Binary files differ
diff --git a/src/main/resources/mixins.notenoughupdates.json b/src/main/resources/mixins.notenoughupdates.json
index 8b1d4559..ed1ba55a 100644
--- a/src/main/resources/mixins.notenoughupdates.json
+++ b/src/main/resources/mixins.notenoughupdates.json
@@ -2,6 +2,7 @@
"package": "io.github.moulberry.notenoughupdates.mixins",
"refmap": "mixins.notenoughupdates.refmap.json",
"minVersion": "0.7",
+ "plugin": "io.github.moulberry.notenoughupdates.envcheck.NEUMixinConfigPlugin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"AccessorEntityAgeable",