Skip to content

Commit 00e65a3

Browse files
committed
feat: fix command source
1 parent a136696 commit 00e65a3

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/main/java/me/matl114/hacks/modules/chat/ClientSideCommand.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import me.matl114.utils.Debug;
2222
import me.matl114.utils.ItemStackUtils;
2323
import me.matl114.events.Event;
24+
import net.minecraft.client.network.ClientCommandSource;
2425
import net.minecraft.command.CommandRegistryAccess;
2526
import net.minecraft.command.CommandSource;
2627
import net.minecraft.command.EntitySelector;
@@ -168,15 +169,15 @@ public void onCommandSend(Event<String> commandEvent){
168169
}
169170

170171

171-
private static ResultConsumer<CommandSource> consumer = (c, s, r) -> {
172+
private static ResultConsumer<ClientCommandSource> consumer = (c, s, r) -> {
172173
};
173174

174175
private boolean dispatchVanillaCommand(String command){
175176
// Debug.info(command);
176177
if(mc.player == null)return false;
177178
mc.player.setClientPermissionLevel(4);
178179
try{
179-
ParseResults<CommandSource> parse = mc.getNetworkHandler().getCommandDispatcher().parse(command, mc.player.getCommandSource());
180+
ParseResults<ClientCommandSource> parse = (ParseResults) mc.getNetworkHandler().getCommandDispatcher().parse(command, (ClientCommandSource) mc.getNetworkHandler().getCommandSource());
180181
if (parse.getReader().canRead()) {
181182
if (parse.getExceptions().size() == 1) {
182183
throw parse.getExceptions().values().iterator().next();
@@ -188,12 +189,12 @@ private boolean dispatchVanillaCommand(String command){
188189
}
189190

190191
final String commandStr = parse.getReader().getString();
191-
final CommandContextBuilder<CommandSource> originalBuilder = parse.getContext();
192+
final CommandContextBuilder<ClientCommandSource> originalBuilder = parse.getContext();
192193
//flatten this
193-
List<CommandContextBuilder<CommandSource>> modifiers = new ArrayList<>();
194-
CommandContextBuilder<CommandSource> contextData = originalBuilder;
194+
List<CommandContextBuilder<ClientCommandSource>> modifiers = new ArrayList<>();
195+
CommandContextBuilder<ClientCommandSource> contextData = originalBuilder;
195196
while (true){
196-
CommandContextBuilder<CommandSource> child = contextData.getChild();
197+
CommandContextBuilder<ClientCommandSource> child = contextData.getChild();
197198
if(child == null){
198199
if(contextData.getCommand() ==null){
199200
consumer.onCommandComplete(originalBuilder.build(commandStr), false, 0);
@@ -204,7 +205,7 @@ private boolean dispatchVanillaCommand(String command){
204205
modifiers.add(contextData);
205206
contextData = child;
206207
}
207-
Map<String, ParsedArgument<CommandSource, ?>> argsMap = contextData.getArguments();
208+
Map<String, ParsedArgument<ClientCommandSource, ?>> argsMap = contextData.getArguments();
208209
if(commandStr.startsWith("give") || commandStr.startsWith("minecraft:give")){
209210
return handleClientSideGiveCommand(argsMap, command);
210211
}
@@ -216,11 +217,11 @@ private boolean dispatchVanillaCommand(String command){
216217
return false;
217218
}
218219

219-
private boolean handleClientSideGiveCommand(Map<String, ParsedArgument<CommandSource, ?>> argsMap, String command) throws CommandSyntaxException{
220+
private boolean handleClientSideGiveCommand(Map<String, ParsedArgument<ClientCommandSource, ?>> argsMap, String command) throws CommandSyntaxException{
220221
if(enableGive.get()){
221222
if(mc.player.isCreative()){
222223
Debug.chat(Text.literal("尝试在客户端执行give指令").formatted(Formatting.GREEN));
223-
ParsedArgument<CommandSource, ?> entityArgument = argsMap.get("targets");
224+
ParsedArgument<ClientCommandSource, ?> entityArgument = argsMap.get("targets");
224225
EntitySelector entitySelector = (EntitySelector) entityArgument.getResult();
225226
StringRange range = entityArgument.getRange();
226227
if(entitySelector.isSenderOnly() || Objects.equals( mc.player.getNameForScoreboard(), command.substring(range.getStart(), range.getEnd()))){

0 commit comments

Comments
 (0)