Feat: Better error handling

This commit is contained in:
xiaozhou233 committed 2026-08-26 12:03:29 +08:00
1 parent 07f4cc0663
commit db6433158f
4 files changed
+38 -5

No files matched your search

@@ -3,7 +3,11 @@ package cn.xiaozhou233.orangex.loader;
import cn.xiaozhou233.juiceagent.api.JuiceAgent;
import cn.xiaozhou233.orangex.loader.classloader.GameClassLoaderResolver;
import javax.swing.*;
import java.io.File;
import java.awt.*;
import java.io.PrintWriter;
import java.io.StringWriter;
public class Loader {
public static String userHome = System.getProperty("user.home");
@@ -24,7 +28,25 @@ public class Loader {
Class<?> orangeXClass = Class.forName("cn.xiaozhou233.orangex.entry.Entry", true, minecraftClassLoader);
orangeXClass.getMethod("entry").invoke(null);
} catch (Exception e) {
throw new RuntimeException(e);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
JTextArea textArea = new JTextArea(sw.toString());
textArea.setEditable(false);
textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 20));
textArea.setLineWrap(false);
textArea.setCaretPosition(0);
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setPreferredSize(new Dimension(1000, 600));
JOptionPane.showMessageDialog(
null,
scrollPane,
"Failed to load OrangeX",
JOptionPane.ERROR_MESSAGE
);
}
System.out.println("======== Loader END ========");
@@ -1,9 +1,13 @@
package cn.xiaozhou233.orangex;
import cn.xiaozhou233.orangex.runtime.RuntimeInfo;
import lombok.Getter;
import lombok.Setter;
import org.greenrobot.eventbus.EventBus;
@Getter
public class OrangeX {
@Setter
private RuntimeInfo runtime = null;
public static final OrangeX INSTANCE = new OrangeX();
private final EventBus eventBus = EventBus.builder()
@@ -16,7 +20,9 @@ public class OrangeX {
public void start() {
System.out.println("OrangeX starting...");
if(runtime==null) {
throw new RuntimeException("Runtime not set.");
}
System.out.println("OrangeX started.");
}
@@ -1,9 +1,15 @@
package cn.xiaozhou233.orangex.entry;
import cn.xiaozhou233.orangex.OrangeX;
import cn.xiaozhou233.orangex.runtime.RuntimeDetector;
import cn.xiaozhou233.orangex.runtime.RuntimeInfo;
public class Entry {
public static void entry() {
RuntimeDetector.debug();
RuntimeInfo runtime = RuntimeDetector.detect();
RuntimeDetector.debug(runtime);
OrangeX.getInstance().setRuntime(runtime);
OrangeX.getInstance().start();
}
}
@@ -14,8 +14,7 @@ public final class RuntimeDetector {
return new RuntimeInfo(classLoader, loaderType, version);
}
public static void debug() {
RuntimeInfo runtime = detect();
public static void debug(RuntimeInfo runtime) {
ClassLoader loader = runtime.getMinecraftClassLoader();
MinecraftVersion version = runtime.getMinecraftVersion();
int protocol = MinecraftVersion.getCurrentProtocolVersion();