Skip to content

Commit e988c73

Browse files
committed
version check & bug fixes
1 parent d42d3ab commit e988c73

5 files changed

Lines changed: 31 additions & 15 deletions

File tree

src/main/java/com/hb/mcfdebugger/commands/DebuggerCommand.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
import com.mojang.brigadier.context.CommandContext;
99
import com.mojang.brigadier.exceptions.CommandSyntaxException;
1010
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
11-
import net.minecraft.command.argument.EntityArgumentType;
12-
import net.minecraft.command.argument.ObjectiveArgumentType;
13-
import net.minecraft.command.argument.ScoreHolderArgumentType;
11+
import net.minecraft.command.argument.*;
1412
import net.minecraft.server.command.CommandManager;
1513
import net.minecraft.server.command.ServerCommandSource;
1614
import net.minecraft.text.TranslatableText;
15+
import net.minecraft.util.math.BlockPos;
16+
import net.minecraft.util.math.Vec2f;
17+
import net.minecraft.world.chunk.Chunk;
18+
import net.minecraft.world.chunk.ChunkStatus;
1719

1820
public class DebuggerCommand {
1921
public static final SimpleCommandExceptionType LOGGER_HIT_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("MCFDEBUGGER: Logger hit."));
2022
public static final SimpleCommandExceptionType CONSOLE_LOG_HIT_EXCEPTION = new SimpleCommandExceptionType(new TranslatableText("MCFDEBUGGER: Logger hit."));
23+
2124
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
2225
LiteralArgumentBuilder<ServerCommandSource> literalArgumentBuilder = CommandManager.literal("debuggerCmd").
2326
requires(source -> source.hasPermissionLevel(2))
@@ -44,13 +47,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
4447
}
4548
)
4649
)
47-
))
48-
.then(CommandManager.literal("all")
49-
.executes((CommandContext<ServerCommandSource> cmd) -> {
50-
return 1;
51-
}
5250
)
53-
5451
)
5552
.then(CommandManager.literal("getEntity")
5653
.then(CommandManager.argument("targets", EntityArgumentType.entities())
@@ -69,15 +66,16 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
6966
}
7067
)
7168

72-
)
69+
)
7370
.then(CommandManager.literal("log")
7471
.executes((CommandContext<ServerCommandSource> cmd) -> {
7572
McfDebugger.nowCommandCount--;
7673
return DebuggerCommand.log(cmd);
7774
}
7875
)
7976

80-
);
77+
)
78+
;
8179
dispatcher.register(literalArgumentBuilder);
8280
}
8381

@@ -117,6 +115,7 @@ public static int loud(CommandContext<ServerCommandSource> cmd) throws CommandSy
117115
}
118116
return 1;
119117
}
118+
120119
public static int log(CommandContext<ServerCommandSource> cmd) throws CommandSyntaxException {
121120
if (!McfDebugger.debuggerMode.equals("none")) {
122121
McfDebugger.nowLogFunNamespace = McfDebugger.lastCmdObj.funNamespace;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.hb.mcfdebugger.mixin;
2+
3+
import net.minecraft.server.command.ServerCommandSource;
4+
import org.spongepowered.asm.mixin.Final;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.Shadow;
7+
8+
@Mixin(ServerCommandSource.class)
9+
public class CommandSourceHook {
10+
@Shadow @Final int level;
11+
public int fakeGetLevel(){
12+
return this.level;
13+
}
14+
}

src/main/java/com/hb/mcfdebugger/mixinHelpers/SendCommandState.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.minecraft.world.World;
1111

1212
import java.lang.reflect.Field;
13+
import java.lang.reflect.Method;
1314
import java.util.LinkedHashMap;
1415
import java.util.Map;
1516

@@ -44,9 +45,8 @@ public static void send(CommandFunction.Element element, ServerCommandSource sou
4445
sourceMap.put("rotation","("+source.getRotation().x+", "+source.getRotation().y+")");
4546
sourceMap.put("world",source.getWorld().getRegistryKey().getValue().toString());
4647
try {
47-
Field levelField = source.getClass().getDeclaredField("level");
48-
levelField.setAccessible(true);
49-
sourceMap.put("level",( levelField.get(source)).toString());
48+
Method levelMethod = source.getClass().getDeclaredMethod("fakeGetLevel");
49+
sourceMap.put("level", String.valueOf(levelMethod.invoke(source)));
5050
} catch (ReflectiveOperationException e) {
5151
sourceMap.put("level","Error");
5252
}

src/main/java/com/hb/mcfdebugger/wsCommandParser.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public ServerCommandSource getSource() {
133133
wsCommandParser.sendMsg("mcfdebugger.reloadCommand");
134134
SendFeedBack("reloaded.","Success");
135135
break;
136+
case "getVersion":
137+
DebugThread.sendObjMsgToDebugger("2","versionResult");
136138
default:
137139
SendFeedBack("Unknown command.","Error");
138140
}

src/main/resources/mcfdebugger.mixins.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"ErrorHook",
1313
"ServerLoad",
1414
"FunctionCommandHook",
15-
"ServerCommandSourceHook"
15+
"ServerCommandSourceHook",
16+
"CommandSourceHook"
1617
],
1718
"client": [
1819
"ExampleMixin"

0 commit comments

Comments
 (0)