From 97a1d784a9220f7e137fdf1e00e5fcbce2459a14 Mon Sep 17 00:00:00 2001 From: RacoonDog <32882447+RacoonDog@users.noreply.github.com> Date: Mon, 6 May 2024 23:47:56 -0400 Subject: [PATCH] use real command source --- .../meteorclient/commands/Command.java | 10 ++++++---- .../meteorclient/commands/Commands.java | 4 +--- .../meteorclient/mixin/ChatInputSuggestorMixin.java | 4 +++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/commands/Command.java b/src/main/java/meteordevelopment/meteorclient/commands/Command.java index 72b7e4b971..10c63e133a 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/Command.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/Command.java @@ -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 aliases = new ArrayList<>(); + private final List 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 diff --git a/src/main/java/meteordevelopment/meteorclient/commands/Commands.java b/src/main/java/meteordevelopment/meteorclient/commands/Commands.java index c01a2cfe43..65325783f3 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/Commands.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/Commands.java @@ -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; @@ -21,7 +20,6 @@ public class Commands { public static final CommandDispatcher DISPATCHER = new CommandDispatcher<>(); - public static final CommandSource COMMAND_SOURCE = new ClientCommandSource(null, mc); public static final List COMMANDS = new ArrayList<>(); @PostInit(dependencies = PathManagers.class) @@ -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) { diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/ChatInputSuggestorMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/ChatInputSuggestorMixin.java index a6e75f91f9..e610790137 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/ChatInputSuggestorMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/ChatInputSuggestorMixin.java @@ -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 parse; @@ -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();