From bbe5ae9b7c6dd1ec29ad17b2e0a92563e8fd132e Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sun, 24 Mar 2024 11:52:32 -0500 Subject: [PATCH] Fix potential issues when java.awt.headless is true --- .../distanthorizons/core/config/Config.java | 20 ++++++++++--- .../core/jar/updater/SelfUpdater.java | 29 +++++++++++++++---- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java index b9c1a0e24..180ab4aeb 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java @@ -37,7 +37,9 @@ import com.seibel.distanthorizons.coreapi.util.StringUtil; import org.apache.logging.log4j.Logger; import javax.swing.*; +import java.awt.*; import java.util.*; +import java.util.List; /** @@ -1423,10 +1425,20 @@ public class Config .set(new HashMap()) .build(); - public static ConfigUIButton uiButtonTest = new ConfigUIButton(() -> { new Thread(() -> { - System.setProperty("java.awt.headless", "false"); // Required to make it work - JOptionPane.showMessageDialog(null, "Button pressed!", "UITester dialog", JOptionPane.INFORMATION_MESSAGE); - });}); + public static ConfigUIButton uiButtonTest = new ConfigUIButton(() -> + { + new Thread(() -> + { + if (!GraphicsEnvironment.isHeadless()) + { + JOptionPane.showMessageDialog(null, "Button pressed!", "UITester dialog", JOptionPane.INFORMATION_MESSAGE); + } + else + { + LOGGER.info("button pressed!"); + } + }); + }); public static ConfigCategory categoryTest = new ConfigCategory.Builder().set(CategoryTest.class).build(); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java index 1bd11960a..16df88e2b 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/jar/updater/SelfUpdater.java @@ -33,6 +33,7 @@ import com.seibel.distanthorizons.coreapi.util.jar.DeleteOnUnlock; import org.apache.logging.log4j.Logger; import javax.swing.*; +import java.awt.*; import java.io.*; import java.net.URLEncoder; import java.nio.file.Files; @@ -222,9 +223,17 @@ public class SelfUpdater deleteOldJarOnJvmShutdown = true; LOGGER.info(ModInfo.READABLE_NAME + " successfully updated. It will apply on game's relaunch"); - new Thread(() -> { - System.setProperty("java.awt.headless", "false"); // Required to make it work - JOptionPane.showMessageDialog(null, ModInfo.READABLE_NAME + " updated, this will be applied on game restart.", ModInfo.READABLE_NAME, JOptionPane.INFORMATION_MESSAGE); + new Thread(() -> + { + String message = ModInfo.READABLE_NAME + " updated, this will be applied on game restart."; + if (!GraphicsEnvironment.isHeadless()) + { + JOptionPane.showMessageDialog(null, message, ModInfo.READABLE_NAME, JOptionPane.INFORMATION_MESSAGE); + } + else + { + LOGGER.info(message); + } }).start(); return true; } @@ -270,9 +279,17 @@ public class SelfUpdater deleteOldJarOnJvmShutdown = true; LOGGER.info(ModInfo.READABLE_NAME + " successfully updated. It will apply on game's relaunch"); - new Thread(() -> { - System.setProperty("java.awt.headless", "false"); // Required to make it work - JOptionPane.showMessageDialog(null, ModInfo.READABLE_NAME + " updated, this will be applied on game restart.", ModInfo.READABLE_NAME, JOptionPane.INFORMATION_MESSAGE); + new Thread(() -> + { + String message = ModInfo.READABLE_NAME + " updated, this will be applied on game restart."; + if (!GraphicsEnvironment.isHeadless()) + { + JOptionPane.showMessageDialog(null, message, ModInfo.READABLE_NAME, JOptionPane.INFORMATION_MESSAGE); + } + else + { + LOGGER.info(message); + } }).start(); zis.close();