Skip to content

Commit

Permalink
1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
hugeBlack committed Mar 7, 2021
1 parent 2f8ef40 commit 6602e65
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 47 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/hb/mcfdebugger/McfDebugger.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ public static void LOG(Object msgObj){
}
}

public static boolean howeverStop = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
public static int execute_getScoreByEntity(CommandContext<ServerCommandSource> cmd) throws CommandSyntaxException {
if (!ConfigHolder.debuggerMode.equals("none")) {
ReadScoreboard.parseScoreboardByEntity(cmd);
McfDebugger.howeverStop=true;
throw LOGGER_HIT_EXCEPTION.create();
} else {
return 1;
Expand All @@ -93,6 +94,7 @@ public static int execute_getScoreByEntity(CommandContext<ServerCommandSource> c
public static int execute_getScoreByObjective(CommandContext<ServerCommandSource> cmd) throws CommandSyntaxException {
if (!ConfigHolder.debuggerMode.equals("none")) {
ReadScoreboard.parseScoreboardByObjective(cmd);
McfDebugger.howeverStop=true;
throw LOGGER_HIT_EXCEPTION.create();
} else {
return 1;
Expand All @@ -102,6 +104,7 @@ public static int execute_getScoreByObjective(CommandContext<ServerCommandSource
public static int getEntity(CommandContext<ServerCommandSource> cmd) throws CommandSyntaxException {
if (!ConfigHolder.debuggerMode.equals("none")) {
GetEntity.get(cmd);
McfDebugger.howeverStop=true;
throw LOGGER_HIT_EXCEPTION.create();
} else {
return 1;
Expand Down
39 changes: 13 additions & 26 deletions src/main/java/com/hb/mcfdebugger/mixin/ErrorHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.hb.mcfdebugger.*;
import com.hb.mcfdebugger.config.ConfigHolder;
import com.hb.mcfdebugger.mixinHelpers.ReadCommandSource;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.function.CommandFunction;
import net.minecraft.server.function.CommandFunctionManager;
Expand All @@ -26,11 +27,11 @@ public void execute(ArrayDeque<CommandFunctionManager.Entry> stack, int maxChain
try {
element.execute(manager, source, stack, maxChainLength);
} catch (Throwable var4) {
if (!ConfigHolder.debuggerMode.equals("none")&&!ConfigHolder.nonStopOnException) {
if (!ConfigHolder.debuggerMode.equals("none")) {
String exceptionMsg = var4.toString();
if (exceptionMsg != "") {
if (McfDebugger.lastCmdObj!=null && !McfDebugger.lastCmdObj.toSimple().isNext(McfDebugger.nowMuteCmd)) {
sendError(exceptionMsg);
sendError(exceptionMsg,ConfigHolder.nonStopOnException?1:0);

}
}
Expand All @@ -40,32 +41,18 @@ public void execute(ArrayDeque<CommandFunctionManager.Entry> stack, int maxChain
McfDebugger.nowMuteCmd.clear();
}
}
public void sendError(String message) {
public void sendError(String message,int mode) {
McfDebugger.lastCmdObj.exception=message;
McfDebugger.lastCmdObj.pause=true;
Map<String,String> sourceMap =new LinkedHashMap<>();
if(source.getEntity()!=null){
sourceMap.put("entityName",source.getEntity().getEntityName());
sourceMap.put("entityUuid",source.getEntity().getUuidAsString());
}else{
sourceMap.put("entityName","None(Server)");
sourceMap.put("entityUuid","None");
}
sourceMap.put("pos" ,source.getPosition().toString());
sourceMap.put("rotation","("+source.getRotation().y+", "+source.getRotation().x+")");
sourceMap.put("world",source.getWorld().getRegistryKey().getValue().toString());
try {
Method levelMethod = source.getClass().getDeclaredMethod("fakeGetLevel");
sourceMap.put("level", String.valueOf(levelMethod.invoke(source)));
} catch (ReflectiveOperationException e) {
sourceMap.put("level","Error");
}
sourceMap.put("commandsLeftToMaxChainLength", String.valueOf(McfDebugger.commandsLeftToMaxChainLength));
SendCmdObj sendCmdObj = new SendCmdObj(McfDebugger.lastCmdObj.funNamespace, McfDebugger.lastCmdObj.funPath, McfDebugger.lastCmdObj.cmdIndex, element.toString(),true,sourceMap);
SendCmdObj sendCmdObj = new SendCmdObj(McfDebugger.lastCmdObj.funNamespace, McfDebugger.lastCmdObj.funPath, McfDebugger.lastCmdObj.cmdIndex, element.toString(),true, ReadCommandSource.read(source));
sendCmdObj.exception=message;
DebugThread.sendObjMsgToDebugger(McfDebugger.stackList,"stackReport");
DebugThread.sendObjMsgToDebugger(sendCmdObj,"errorCommandReport");

PauseWaiter.WaitForNext();
if(mode==0||McfDebugger.howeverStop){
McfDebugger.howeverStop=false;
DebugThread.sendObjMsgToDebugger(McfDebugger.stackList,"stackReport");
DebugThread.sendObjMsgToDebugger(sendCmdObj,"errorCommandReport");
PauseWaiter.WaitForNext();
}else if (mode==1){
DebugThread.sendObjMsgToDebugger(sendCmdObj,"nonStopErrorCommandReport");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static CommandFunction create(Identifier id, CommandDispatcher<ServerComm
//modified
ParseResults<ServerCommandSource> parseResults;

if(!string.substring(0,2).equals("#@")){
if(!string.startsWith("#@")){
parseResults = commandDispatcher.parse(stringReader, serverCommandSource);
}else{
parseResults = commandDispatcher.parse(new StringReader("debuggerCmd "+string.substring(2)), serverCommandSource);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.hb.mcfdebugger.mixinHelpers;

import com.hb.mcfdebugger.McfDebugger;
import net.minecraft.server.command.ServerCommandSource;

import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.Map;

public class ReadCommandSource {
public static Map<String,String> read(ServerCommandSource source){
Map<String,String> sourceMap =new LinkedHashMap<>();
if(source.getEntity()!=null){
sourceMap.put("entityName",source.getEntity().getEntityName());
sourceMap.put("entityUuid",source.getEntity().getUuidAsString());
}else{
sourceMap.put("entityName","None(Server)");
sourceMap.put("entityUuid","None");
}
sourceMap.put("pos" ,source.getPosition().toString());
sourceMap.put("rotation","("+source.getRotation().y+", "+source.getRotation().x+")");
sourceMap.put("world",source.getWorld().getRegistryKey().getValue().toString());
try {
Method levelMethod = source.getClass().getDeclaredMethod("fakeGetLevel");
sourceMap.put("level", String.valueOf(levelMethod.invoke(source)));
} catch (ReflectiveOperationException e) {
sourceMap.put("level","Error");
}
sourceMap.put("commandsLeftToMaxChainLength", String.valueOf(McfDebugger.commandsLeftToMaxChainLength));
return sourceMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,7 @@ public static void send(CommandFunction.Element element, ServerCommandSource sou
}

if(ConfigHolder.debuggerMode.equals("byStep")|| wsCommandParser.isInPauseList(funNamespace,funPath,cmdIndex)){

Map<String,String> sourceMap =new LinkedHashMap<>();
if(source.getEntity()!=null){
sourceMap.put("entityName",source.getEntity().getEntityName());
sourceMap.put("entityUuid",source.getEntity().getUuidAsString());
}else{
sourceMap.put("entityName","None(Server)");
sourceMap.put("entityUuid","None");
}
sourceMap.put("pos" ,source.getPosition().toString());
sourceMap.put("rotation","("+source.getRotation().x+", "+source.getRotation().y+")");
sourceMap.put("world",source.getWorld().getRegistryKey().getValue().toString());
try {
Method levelMethod = source.getClass().getDeclaredMethod("fakeGetLevel");
sourceMap.put("level",String.valueOf(levelMethod.invoke(source)));
} catch (ReflectiveOperationException e) {
DebugThread.sendObjMsgToDebugger(e.getMessage(),"e");
}
sourceMap.put("commandsLeftToMaxChainLength", String.valueOf(McfDebugger.commandsLeftToMaxChainLength));
SendCmdObj sendCmdObj = new SendCmdObj(funNamespace, funPath, cmdIndex, element.toString(),true,sourceMap);
SendCmdObj sendCmdObj = new SendCmdObj(funNamespace, funPath, cmdIndex, element.toString(),true,ReadCommandSource.read(source));
McfDebugger.lastCmdObj=sendCmdObj;
DebugThread.sendObjMsgToDebugger(McfDebugger.stackList,"stackReport");
DebugThread.sendObjMsgToDebugger(sendCmdObj,"commandReport");
Expand Down

0 comments on commit 6602e65

Please sign in to comment.