aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-22 01:38:13 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-22 01:38:13 +0200
commite82ae67285539475a33f2942ed6c3b35d7ad65fe (patch)
tree60515e615e69a129d74e834ebbb0ea1e450578d2 /src/main/java
parentf8f97e5626a25f76a8434f5f714420f5179e3213 (diff)
downloadskyhanni-e82ae67285539475a33f2942ed6c3b35d7ad65fe.tar.gz
skyhanni-e82ae67285539475a33f2942ed6c3b35d7ad65fe.tar.bz2
skyhanni-e82ae67285539475a33f2942ed6c3b35d7ad65fe.zip
Show popup with warning when neu version is outdated or missing
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUVersionCheck.kt117
2 files changed, 122 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
index 056a6f9e7..5f54760b9 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
@@ -65,6 +65,7 @@ import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper;
import at.hannibal2.skyhanni.test.LorenzTest;
import at.hannibal2.skyhanni.test.PacketTest;
import at.hannibal2.skyhanni.utils.MinecraftConsoleFilter;
+import at.hannibal2.skyhanni.utils.NEUVersionCheck;
import at.hannibal2.skyhanni.utils.TabListData;
import kotlin.coroutines.EmptyCoroutineContext;
import kotlinx.coroutines.*;
@@ -85,8 +86,8 @@ import java.util.ArrayList;
import java.util.List;
@Mod(modid = SkyHanniMod.MODID, clientSideOnly = true, useMetadata = true,
- guiFactory = "at.hannibal2.skyhanni.config.ConfigGuiForgeInterop",
- dependencies = SkyHanniMod.DEPENDENCIES)
+ guiFactory = "at.hannibal2.skyhanni.config.ConfigGuiForgeInterop"
+)
public class SkyHanniMod {
public static final String MODID = "skyhanni";
@@ -95,8 +96,6 @@ public class SkyHanniMod {
return Loader.instance().getIndexedModList().get(MODID).getVersion();
}
- public static final String DEPENDENCIES = "after:notenoughupdates@[2.1.1,);";
-
public static Features feature;
public static RepoManager repo;
@@ -116,6 +115,8 @@ public class SkyHanniMod {
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
+ NEUVersionCheck.checkIfNeuIsLoaded();
+
logger = LogManager.getLogger("SkyHanni");
// utils
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUVersionCheck.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUVersionCheck.kt
new file mode 100644
index 000000000..6b9e56145
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUVersionCheck.kt
@@ -0,0 +1,117 @@
+package at.hannibal2.skyhanni.utils
+
+import net.minecraftforge.fml.common.FMLCommonHandler
+import java.awt.Desktop
+import java.awt.event.MouseAdapter
+import java.awt.event.MouseEvent
+import java.net.URI
+import javax.swing.JButton
+import javax.swing.JFrame
+import javax.swing.JOptionPane
+import javax.swing.UIManager
+
+object NEUVersionCheck {
+
+ @JvmStatic
+ fun checkIfNeuIsLoaded() {
+ try {
+ Class.forName("io.github.moulberry.notenoughupdates.NotEnoughUpdates")
+ } catch (e: Throwable) {
+ neuWarning(
+ "NotEnoughUpdates is missing!\n" +
+ "SkyHanni requires the latest version of NotEnoughUpdates to work.\n" +
+ "Use these links to download the latest version:"
+ )
+ return
+ }
+
+ try {
+ val clazz = Class.forName("io.github.moulberry.notenoughupdates.util.ItemResolutionQuery")
+
+ for (field in clazz.methods) {
+ if (field.name == "findInternalNameByDisplayName") return
+ }
+ } catch (_: Throwable) {
+ }
+ outdated()
+ }
+
+ private fun outdated() {
+ neuWarning(
+ "NotEnoughUpdates is outdated!\n" +
+ "SkyHanni requires the latest version of NotEnoughUpdates to work.\n" +
+ "Use these links to download the latest version:"
+ )
+ }
+
+ private fun neuWarning(text: String) {
+ openPopupWindow(
+ text,
+ Pair("Join SkyHanni Discord", "https://discord.com/invite/8DXVN4BJz3"),
+ Pair("Open SkyHanni GitHub", "https://github.com/hannibal002/SkyHanni"),
+ Pair("Join NEU Discord", "https://discord.gg/moulberry"),
+ Pair("Open NEU GitHub", "https://github.com/NotEnoughUpdates/NotEnoughUpdates"),
+ )
+ closeMinecraft()
+ }
+
+ /**
+ * Taken and modified from Skytils
+ */
+ private fun openPopupWindow(errorMessage: String, vararg options: Pair<String, String>) {
+ try {
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
+ } catch (e: java.lang.Exception) {
+ e.printStackTrace()
+ }
+
+ val frame = JFrame()
+ frame.isUndecorated = true
+ frame.isAlwaysOnTop = true
+ frame.setLocationRelativeTo(null)
+ frame.isVisible = true
+
+ val buttons = mutableListOf<JButton>()
+ for ((name, link) in options) {
+ val button = JButton(name)
+ button.addMouseListener(object : MouseAdapter() {
+ override fun mouseClicked(event: MouseEvent) {
+ try {
+ Desktop.getDesktop().browse(URI(link))
+ } catch (e: java.lang.Exception) {
+ e.printStackTrace()
+ }
+ }
+ })
+ buttons.add(button)
+ }
+ val close = JButton("Close")
+ close.addMouseListener(object : MouseAdapter() {
+ override fun mouseClicked(event: MouseEvent) {
+ try {
+ closeMinecraft()
+ } catch (e: java.lang.Exception) {
+ e.printStackTrace()
+ }
+ }
+ })
+ buttons.add(close)
+
+ val allOptions = buttons.toTypedArray()
+ JOptionPane.showOptionDialog(
+ frame,
+ errorMessage,
+ "SkyHanni Error",
+ JOptionPane.DEFAULT_OPTION,
+ JOptionPane.ERROR_MESSAGE,
+ null,
+ allOptions,
+ allOptions[0]
+ )
+ }
+
+ fun closeMinecraft() {
+ FMLCommonHandler.instance().handleExit(-1)
+ FMLCommonHandler.instance().expectServerStopped()
+ }
+} \ No newline at end of file