Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: ChatUtils.consoleError() #2976

Merged
merged 3 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 = "";
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -29,7 +30,7 @@ public void acceptOptions(List<String> 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();
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/ChatUtils.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -316,4 +317,8 @@ object ChatUtils {
replaceSameMessage = true,
)
}

fun consoleError(message: String) {
System.err.println(" \nSkyHanni-${SkyHanniMod.version} $message\n ")
}
}
7 changes: 3 additions & 4 deletions src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,9 @@ object LorenzUtils {
inline fun <reified T : Enum<T>> 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" }.orEmpty()
ChatUtils.consoleError("forced the game to shutdown.$reasonLine")

FMLCommonHandler.instance().handleExit(-1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down
Loading