aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-10-07 13:33:51 +0200
committerGitHub <noreply@github.com>2024-10-07 13:33:51 +0200
commitf53fbddd604fd795780f16c25f57378c32d18763 (patch)
tree31e9f2f20f1b5b0c72c36892af49a89c08c5b784 /src/main/java
parent266d007da9f23b19f8e815da3005451195a33a5e (diff)
downloadskyhanni-f53fbddd604fd795780f16c25f57378c32d18763.tar.gz
skyhanni-f53fbddd604fd795780f16c25f57378c32d18763.tar.bz2
skyhanni-f53fbddd604fd795780f16c25f57378c32d18763.zip
Backend: More /shdebug (#2691)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/tweaker/DownloadSourceChecker.java4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/tweaker/TweakerUtils.java4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ComputerEnvDebug.kt107
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt11
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt30
6 files changed, 149 insertions, 12 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
index f34dafb3b..3707d10af 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
@@ -195,6 +195,11 @@ object HypixelData {
@SubscribeEvent
fun onDebugDataCollect(event: DebugDataCollectEvent) {
event.title("Server ID")
+ if (!LorenzUtils.inSkyBlock) {
+ event.addIrrelevant("not in sb")
+ return
+ }
+
val id = serverId
if (id == null) {
event.addData {
diff --git a/src/main/java/at/hannibal2/skyhanni/tweaker/DownloadSourceChecker.java b/src/main/java/at/hannibal2/skyhanni/tweaker/DownloadSourceChecker.java
index 2c417909e..7947b6ebc 100644
--- a/src/main/java/at/hannibal2/skyhanni/tweaker/DownloadSourceChecker.java
+++ b/src/main/java/at/hannibal2/skyhanni/tweaker/DownloadSourceChecker.java
@@ -1,5 +1,7 @@
package at.hannibal2.skyhanni.tweaker;
+import at.hannibal2.skyhanni.utils.OSUtils;
+
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
@@ -32,7 +34,7 @@ public class DownloadSourceChecker {
};
public static void init() {
- if (!TweakerUtils.isOnWindows()) return;
+ if (!OSUtils.INSTANCE.isWindows()) return;
URI host = getDangerousHost();
if (host != null) {
openMenu(host);
diff --git a/src/main/java/at/hannibal2/skyhanni/tweaker/TweakerUtils.java b/src/main/java/at/hannibal2/skyhanni/tweaker/TweakerUtils.java
index b9070e0c1..ffd415c10 100644
--- a/src/main/java/at/hannibal2/skyhanni/tweaker/TweakerUtils.java
+++ b/src/main/java/at/hannibal2/skyhanni/tweaker/TweakerUtils.java
@@ -11,10 +11,6 @@ import java.security.PrivilegedAction;
public class TweakerUtils {
- public static boolean isOnWindows() {
- return System.getProperty("os.name").toLowerCase().contains("win");
- }
-
public static void openUrl(String url) {
try {
Desktop.getDesktop().browse(new URI(url));
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ComputerEnvDebug.kt b/src/main/java/at/hannibal2/skyhanni/utils/ComputerEnvDebug.kt
new file mode 100644
index 000000000..ca4eeeb71
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ComputerEnvDebug.kt
@@ -0,0 +1,107 @@
+package at.hannibal2.skyhanni.utils
+
+import at.hannibal2.skyhanni.events.DebugDataCollectEvent
+import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
+import at.hannibal2.skyhanni.test.command.ErrorManager
+import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.system.PlatformUtils
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+@SkyHanniModule
+object ComputerEnvDebug {
+
+ @SubscribeEvent
+ fun onDebugDataCollect(event: DebugDataCollectEvent) {
+ os(event)
+ java(event)
+ launcher(event)
+ }
+
+ private fun launcher(event: DebugDataCollectEvent) {
+ event.title("Computer Minecraft Launcher")
+
+ val firstStack = getFirstStack() ?: run {
+ event.addData("Could not load data!")
+ return
+ }
+
+ val (launcher, relevant) = findLauncher(firstStack)
+
+ launcher?.let {
+ if (relevant) {
+ event.addData(it)
+ } else {
+ event.addIrrelevant(it)
+ }
+ return
+ }
+
+ event.addData {
+ add("Unknown launcher!")
+ add("firstStack: '$firstStack'")
+ }
+ }
+
+ // TODO put into repo
+ private fun findLauncher(firstStack: String): Pair<String?, Boolean> {
+ if (firstStack.contains("net.fabricmc.devlaunchinjector.Main.main")) {
+ return Pair("Dev Env", false)
+ }
+ if (firstStack.contains("net.minecraft.launchwrapper.Launch.main")) {
+ return Pair("Vanilla Launcher", false)
+ }
+ if (firstStack.contains("org.prismlauncher.EntryPoint.main")) {
+ return Pair("Prism", false)
+ }
+ if (firstStack.contains("net.digitalingot.vendor.")) {
+ return Pair("Feather Client", true)
+ }
+ return Pair(null, true)
+ }
+
+ private fun getFirstStack(): String? {
+ val firstStack = try {
+ Thread.currentThread().stackTrace.last().toString()
+ } catch (e: Exception) {
+ ErrorManager.logErrorWithData(e, "Failed loading current thread stack trace info")
+ null
+ }
+ return firstStack
+ }
+
+ private fun java(event: DebugDataCollectEvent) {
+ event.title("Computer Java Version")
+ val version = System.getProperty("java.version")
+ val pattern = "1\\.8\\.0_(?<update>.*)".toPattern()
+ pattern.matchMatcher(version) {
+ group("update").toIntOrNull()?.let {
+ val devEnvironment = PlatformUtils.isDevEnvironment
+ if (it < 300 && !devEnvironment) {
+ event.addData("Old update: $it")
+ } else {
+ if (devEnvironment) {
+ event.addIrrelevant("Update version: $it (dev env)")
+ } else {
+ event.addIrrelevant("New update: $it")
+ }
+ }
+ return
+ }
+ }
+ event.addData("Unknwon java version: '$version'")
+ }
+
+ private fun os(event: DebugDataCollectEvent) {
+ event.title("Computer Operating System")
+ val osType = OSUtils.getOperatingSystem()
+ val exactName = OSUtils.getOperatingSystemRaw()
+ if (osType != OSUtils.OperatingSystem.UNKNOWN) {
+ event.addIrrelevant {
+ add("OS type: $osType")
+ add("Exact name: $exactName")
+ }
+ } else {
+ event.addData("Unknwon OS: '$exactName'")
+ }
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt b/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt
index 83ea15ecc..c0f65645a 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt
@@ -112,11 +112,16 @@ object ComputerTimeOffset {
@SubscribeEvent
fun onDebugCollect(event: DebugDataCollectEvent) {
event.title("Time Offset")
- val relevant = offsetMillis?.absoluteValue?.let { it < 100.milliseconds } ?: true
+ val offset = offsetMillis ?: run {
+ event.addIrrelevant("not calculated yet")
+ return
+ }
+
+ val relevant = offset.absoluteValue > 500.milliseconds
if (relevant) {
- event.addData(offsetMillis.toString())
+ event.addData(offset.toString())
} else {
- event.addIrrelevant(offsetMillis.toString())
+ event.addIrrelevant(offset.toString())
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt
index 5b42c5dc6..ecd0f0650 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/OSUtils.kt
@@ -7,15 +7,37 @@ import java.net.URI
object OSUtils {
+ enum class OperatingSystem {
+ LINUX,
+ SOLARIS,
+ WINDOWS,
+ MACOS,
+ UNKNOWN,
+ }
+
+ fun getOperatingSystemRaw(): String = System.getProperty("os.name")
+
+ fun getOperatingSystem(): OperatingSystem {
+ val osName = getOperatingSystemRaw().lowercase()
+ return when {
+ osName.contains("win") -> OperatingSystem.WINDOWS
+ osName.contains("mac") -> OperatingSystem.MACOS
+ osName.contains("solaris") || osName.contains("sunos") -> OperatingSystem.SOLARIS
+ osName.contains("linux") || osName.contains("unix") -> OperatingSystem.LINUX
+
+ else -> OperatingSystem.UNKNOWN
+ }
+ }
+
val isWindows: Boolean
val isMac: Boolean
val isLinux: Boolean
init {
- val os = System.getProperty("os.name")
- isWindows = os.contains("win", ignoreCase = true)
- isMac = os.contains("mac", ignoreCase = true)
- isLinux = os.contains("linux", ignoreCase = true)
+ val os = getOperatingSystem()
+ isWindows = os == OperatingSystem.WINDOWS
+ isMac = os == OperatingSystem.MACOS
+ isLinux = os == OperatingSystem.LINUX
}
@JvmStatic