Skip to content

use real command source for meteor commands #4575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,34 @@
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.systems.config.Config;
import meteordevelopment.meteorclient.utils.Utils;
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.CommandSource;
import net.minecraft.registry.BuiltinRegistries;
import net.minecraft.server.command.CommandManager;
import net.minecraft.text.Text;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public abstract class Command {
protected static final CommandRegistryAccess REGISTRY_ACCESS = CommandManager.createRegistryAccess(BuiltinRegistries.createWrapperLookup());
protected static final int SINGLE_SUCCESS = com.mojang.brigadier.Command.SINGLE_SUCCESS;
protected static final MinecraftClient mc = MeteorClient.mc;

private final String name;
private final String title;
private final String description;
private final List<String> aliases = new ArrayList<>();
private final List<String> aliases;

public Command(String name, String description, String... aliases) {
this.name = name;
this.title = Utils.nameToTitle(name);
this.description = description;
Collections.addAll(this.aliases, aliases);
this.aliases = List.of(aliases);
}

// Helper methods to painlessly infer the CommandSource generic type argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import meteordevelopment.meteorclient.commands.commands.*;
import meteordevelopment.meteorclient.pathing.PathManagers;
import meteordevelopment.meteorclient.utils.PostInit;
import net.minecraft.client.network.ClientCommandSource;
import net.minecraft.command.CommandSource;

import java.util.ArrayList;
Expand All @@ -21,7 +20,6 @@

public class Commands {
public static final CommandDispatcher<CommandSource> DISPATCHER = new CommandDispatcher<>();
public static final CommandSource COMMAND_SOURCE = new ClientCommandSource(null, mc);
public static final List<Command> COMMANDS = new ArrayList<>();

@PostInit(dependencies = PathManagers.class)
Expand Down Expand Up @@ -74,7 +72,7 @@ public static void add(Command command) {
}

public static void dispatch(String message) throws CommandSyntaxException {
DISPATCHER.execute(message, COMMAND_SOURCE);
DISPATCHER.execute(message, mc.getNetworkHandler().getCommandSource());
}

public static Command get(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import java.util.concurrent.CompletableFuture;

import static meteordevelopment.meteorclient.MeteorClient.mc;

@Mixin(ChatInputSuggestor.class)
public abstract class ChatInputSuggestorMixin {
@Shadow private ParseResults<CommandSource> parse;
Expand All @@ -46,7 +48,7 @@ public void onRefresh(CallbackInfo ci, String string, StringReader reader) {
reader.setCursor(reader.getCursor() + length);

if (this.parse == null) {
this.parse = Commands.DISPATCHER.parse(reader, Commands.COMMAND_SOURCE);
this.parse = Commands.DISPATCHER.parse(reader, mc.getNetworkHandler().getCommandSource());
}

int cursor = textField.getCursor();
Expand Down
Loading