From e53931a9e8542380cebad2613f978b48845720e7 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 23 Nov 2024 13:01:57 +0100 Subject: [PATCH 1/3] added and used ChatUtils.consoleError() --- .../at/hannibal2/skyhanni/tweaker/ModLoadingTweaker.java | 3 ++- src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt | 5 +++++ src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt | 7 +++---- .../java/at/hannibal2/skyhanni/utils/NEUVersionCheck.kt | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/tweaker/ModLoadingTweaker.java b/src/main/java/at/hannibal2/skyhanni/tweaker/ModLoadingTweaker.java index 418fa62efe27..78383dcf0c6f 100644 --- a/src/main/java/at/hannibal2/skyhanni/tweaker/ModLoadingTweaker.java +++ b/src/main/java/at/hannibal2/skyhanni/tweaker/ModLoadingTweaker.java @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.tweaker; +import at.hannibal2.skyhanni.utils.ChatUtils; import net.minecraft.launchwrapper.ITweaker; import net.minecraft.launchwrapper.LaunchClassLoader; import net.minecraftforge.fml.relauncher.CoreModManager; @@ -29,7 +30,7 @@ public void acceptOptions(List args, File gameDir, File assetsDir, Strin CoreModManager.getIgnoredMods().remove(file); CoreModManager.getReparseableCoremods().add(file); } catch (URISyntaxException e) { - System.err.println("SkyHanni could not re-add itself as mod."); + ChatUtils.INSTANCE.consoleError("could not re-add itself as mod."); e.printStackTrace(); } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt index f3cd1e1e3e46..a01f1c281806 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.utils +import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.MessageSendToServerEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule @@ -316,4 +317,8 @@ object ChatUtils { replaceSameMessage = true, ) } + + fun consoleError(message: String) { + System.err.println(" \nSkyHanni-${SkyHanniMod.version} $message\n ") + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 57f05df9f85d..7bbf105421ad 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -319,10 +319,9 @@ object LorenzUtils { inline fun > T.isAnyOf(vararg array: T): Boolean = array.contains(this) fun shutdownMinecraft(reason: String? = null) { - System.err.println("SkyHanni-${SkyHanniMod.version} forced the game to shutdown.") - reason?.let { - System.err.println("Reason: $it") - } + val reasonLine = reason?.let { " Reason: $it" } ?: "" + ChatUtils.consoleError("forced the game to shutdown.$reasonLine") + FMLCommonHandler.instance().handleExit(-1) } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUVersionCheck.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUVersionCheck.kt index be5bad5311ad..705231447d0f 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUVersionCheck.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUVersionCheck.kt @@ -39,6 +39,7 @@ object NEUVersionCheck { } private fun neuWarning(what: String) { + ChatUtils.consoleError("failed to find NotEnoughUpdates! Reason: $what") openPopupWindow( "NotEnoughUpdates is $what!\n" + "SkyHanni requires the latest version of NotEnoughUpdates to work.\n" + From 026e446d3118907028bcdfc6d83563de05fb897b Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 23 Nov 2024 13:05:12 +0100 Subject: [PATCH 2/3] added error message for untrusted download source host --- .../hannibal2/skyhanni/tweaker/DownloadSourceChecker.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/tweaker/DownloadSourceChecker.java b/src/main/java/at/hannibal2/skyhanni/tweaker/DownloadSourceChecker.java index 8596b5fb2e47..8148b75064de 100644 --- a/src/main/java/at/hannibal2/skyhanni/tweaker/DownloadSourceChecker.java +++ b/src/main/java/at/hannibal2/skyhanni/tweaker/DownloadSourceChecker.java @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.tweaker; +import at.hannibal2.skyhanni.utils.ChatUtils; import at.hannibal2.skyhanni.utils.OSUtils; import javax.swing.JFrame; @@ -82,7 +83,8 @@ private static void openMenu(URI host) { // Compile the regex pattern for matching an empty host Pattern pattern = Pattern.compile("https:\\/\\/.*.com\\/$|about:internet"); - Matcher matcher = pattern.matcher(uriToSimpleString(host)); + String readableHost = uriToSimpleString(host); + Matcher matcher = pattern.matcher(readableHost); // Check if the host is empty (Brave is cutting everything past .com/ from the host) String cutHostMessage = ""; @@ -91,9 +93,10 @@ private static void openMenu(URI host) { "Try downloading the file using a different browser (Microsoft Edge, Google Chrome, etc.)."; } + ChatUtils.INSTANCE.consoleError("detected a untrusted download source host: '" + readableHost + "'"); JOptionPane.showOptionDialog( frame, - String.format(String.join("\n", SECURITY_POPUP), uriToSimpleString(host)) + cutHostMessage, + String.format(String.join("\n", SECURITY_POPUP), readableHost) + cutHostMessage, "SkyHanni " + MOD_VERSION + " Security Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, From 30626a0e15a31ca70ce5ad312ffdb6996269b364 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 23 Nov 2024 13:15:14 +0100 Subject: [PATCH 3/3] orEmpty --- src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 7bbf105421ad..376406e8c4b0 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -319,7 +319,7 @@ object LorenzUtils { inline fun > T.isAnyOf(vararg array: T): Boolean = array.contains(this) fun shutdownMinecraft(reason: String? = null) { - val reasonLine = reason?.let { " Reason: $it" } ?: "" + val reasonLine = reason?.let { " Reason: $it" }.orEmpty() ChatUtils.consoleError("forced the game to shutdown.$reasonLine") FMLCommonHandler.instance().handleExit(-1)