|
3 | 3 | import com.hb.mcfdebugger.*; |
4 | 4 | import com.hb.mcfdebugger.config.ConfigHolder; |
5 | 5 | import com.hb.mcfdebugger.mixinHelpers.ReadCommandSource; |
| 6 | +import com.mojang.brigadier.exceptions.CommandSyntaxException; |
6 | 7 | import net.minecraft.server.command.ServerCommandSource; |
7 | 8 | import net.minecraft.server.function.CommandFunction; |
8 | 9 | import net.minecraft.server.function.CommandFunctionManager; |
| 10 | +import org.jetbrains.annotations.Nullable; |
9 | 11 | import org.spongepowered.asm.mixin.Final; |
10 | 12 | import org.spongepowered.asm.mixin.Mixin; |
11 | 13 | import org.spongepowered.asm.mixin.Overwrite; |
|
14 | 16 | import java.lang.reflect.Field; |
15 | 17 | import java.lang.reflect.Method; |
16 | 18 | import java.util.ArrayDeque; |
| 19 | +import java.util.Deque; |
17 | 20 | import java.util.LinkedHashMap; |
18 | 21 | import java.util.Map; |
19 | 22 |
|
20 | 23 | @Mixin(CommandFunctionManager.Entry.class) |
21 | 24 | public class ErrorHook { |
22 | | - @Shadow @Final CommandFunctionManager manager; |
23 | 25 | @Shadow @Final ServerCommandSource source; |
| 26 | + @Shadow @Final int depth; |
24 | 27 | @Shadow @Final CommandFunction.Element element; |
25 | 28 | @Overwrite |
26 | | - public void execute(ArrayDeque<CommandFunctionManager.Entry> stack, int maxChainLength) { |
| 29 | + public void execute(CommandFunctionManager manager, Deque<CommandFunctionManager.Entry> entries, int maxChainLength, @Nullable CommandFunctionManager.Tracer tracer) { |
27 | 30 | try { |
28 | | - element.execute(manager, source, stack, maxChainLength); |
29 | | - } catch (Throwable var4) { |
30 | | - if (!ConfigHolder.debuggerMode.equals("none")) { |
31 | | - String exceptionMsg = var4.toString(); |
32 | | - if (exceptionMsg != "") { |
33 | | - if (McfDebugger.lastCmdObj!=null && !McfDebugger.lastCmdObj.toSimple().isNext(McfDebugger.nowMuteCmd)) { |
34 | | - sendError(exceptionMsg,ConfigHolder.nonStopOnException?1:0); |
35 | | - |
36 | | - } |
37 | | - } |
| 31 | + this.element.execute(manager, this.source, entries, maxChainLength, this.depth, tracer); |
| 32 | + } catch (CommandSyntaxException var6) { |
| 33 | + if (tracer != null) { |
| 34 | + tracer.traceError(this.depth, var6.getRawMessage().getString()); |
| 35 | + } |
| 36 | + sendError(var6); |
| 37 | + } catch (Exception var7) { |
| 38 | + if (tracer != null) { |
| 39 | + tracer.traceError(this.depth, var7.getMessage()); |
38 | 40 | } |
| 41 | + sendError(var7); |
39 | 42 | } |
40 | 43 | if (McfDebugger.lastCmdObj!=null && McfDebugger.lastCmdObj.toSimple().isNext(McfDebugger.nowMuteCmd)) { |
41 | 44 | McfDebugger.nowMuteCmd.clear(); |
42 | 45 | } |
43 | 46 | } |
44 | | - public void sendError(String message,int mode) { |
45 | | - McfDebugger.lastCmdObj.exception=message; |
46 | | - McfDebugger.lastCmdObj.pause=true; |
47 | | - SendCmdObj sendCmdObj = new SendCmdObj(McfDebugger.lastCmdObj.funNamespace, McfDebugger.lastCmdObj.funPath, McfDebugger.lastCmdObj.cmdIndex, element.toString(),true, ReadCommandSource.read(source)); |
48 | | - sendCmdObj.exception=message; |
49 | | - if(mode==0||McfDebugger.howeverStop){ |
50 | | - McfDebugger.howeverStop=false; |
51 | | - DebugThread.sendObjMsgToDebugger(McfDebugger.stackList,"stackReport"); |
52 | | - DebugThread.sendObjMsgToDebugger(sendCmdObj,"errorCommandReport"); |
53 | | - PauseWaiter.WaitForNext(); |
54 | | - }else if (mode==1){ |
55 | | - DebugThread.sendObjMsgToDebugger(sendCmdObj,"nonStopErrorCommandReport"); |
| 47 | + public void sendError(Exception exception) { |
| 48 | + if (!ConfigHolder.debuggerMode.equals("none")) { |
| 49 | + String exceptionMsg = exception.toString(); |
| 50 | + if (exceptionMsg != "") { |
| 51 | + if (McfDebugger.lastCmdObj!=null && !McfDebugger.lastCmdObj.toSimple().isNext(McfDebugger.nowMuteCmd)) { |
| 52 | + int mode=ConfigHolder.nonStopOnException?1:0; |
| 53 | + McfDebugger.lastCmdObj.exception=exceptionMsg; |
| 54 | + McfDebugger.lastCmdObj.pause=true; |
| 55 | + SendCmdObj sendCmdObj = new SendCmdObj(McfDebugger.lastCmdObj.funNamespace, McfDebugger.lastCmdObj.funPath, McfDebugger.lastCmdObj.cmdIndex, element.toString(),true, ReadCommandSource.read(source)); |
| 56 | + sendCmdObj.exception=exceptionMsg; |
| 57 | + if(mode==0||McfDebugger.howeverStop){ |
| 58 | + McfDebugger.howeverStop=false; |
| 59 | + DebugThread.sendObjMsgToDebugger(McfDebugger.stackList,"stackReport"); |
| 60 | + DebugThread.sendObjMsgToDebugger(sendCmdObj,"errorCommandReport"); |
| 61 | + PauseWaiter.WaitForNext(); |
| 62 | + }else if (mode==1){ |
| 63 | + DebugThread.sendObjMsgToDebugger(sendCmdObj,"nonStopErrorCommandReport"); |
| 64 | + } |
| 65 | + } |
| 66 | + } |
56 | 67 | } |
| 68 | + |
57 | 69 | } |
58 | 70 | } |
0 commit comments