mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 19:56:15 +00:00
Compare commits
2 commits
e13b035b10
...
b613c10565
| Author | SHA1 | Date | |
|---|---|---|---|
| b613c10565 | |||
| cf428682a2 |
4 changed files with 50 additions and 8 deletions
|
|
@ -8,6 +8,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|||
import land.chipmunk.chipmunkmod.commands.*;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.command.CommandRegistryAccess;
|
||||
import net.minecraft.text.ClickEvent;
|
||||
import net.minecraft.text.MutableText;
|
||||
|
|
@ -37,6 +38,7 @@ public class CommandManager {
|
|||
AutoSkinCommand.register(this.dispatcher);
|
||||
ReloadConfigCommand.register(this.dispatcher);
|
||||
SelfCareCommand.register(this.dispatcher);
|
||||
PrefixCommand.register(this.dispatcher);
|
||||
}
|
||||
|
||||
public static LiteralArgumentBuilder<FabricClientCommandSource> literal (final String name) {
|
||||
|
|
@ -49,8 +51,11 @@ public class CommandManager {
|
|||
|
||||
public void executeCommand (final String command) {
|
||||
final MinecraftClient client = MinecraftClient.getInstance();
|
||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||
|
||||
final FabricClientCommandSource commandSource = (FabricClientCommandSource) client.getNetworkHandler().getCommandSource();
|
||||
if (networkHandler == null) return;
|
||||
|
||||
final FabricClientCommandSource commandSource = (FabricClientCommandSource) networkHandler.getCommandSource();
|
||||
|
||||
try {
|
||||
dispatcher.execute(command, commandSource);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package land.chipmunk.chipmunkmod.commands;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||
import land.chipmunk.chipmunkmod.command.CommandManager;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.*;
|
||||
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
|
||||
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
|
||||
|
||||
public class PrefixCommand {
|
||||
public static void register (final CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
dispatcher.register(
|
||||
literal("prefix")
|
||||
.then(
|
||||
argument("newPrefix", greedyString())
|
||||
.executes(PrefixCommand::execute)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static int execute (final CommandContext<FabricClientCommandSource> context) {
|
||||
final FabricClientCommandSource source = context.getSource();
|
||||
|
||||
final String prefix = getString(context, "newPrefix");
|
||||
|
||||
ChipmunkMod.CONFIG.commands.prefix = prefix;
|
||||
CommandManager.INSTANCE.prefix = prefix;
|
||||
|
||||
source.sendFeedback(Text.literal("Set the command prefix to: " + prefix));
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package land.chipmunk.chipmunkmod.mixin;
|
|||
|
||||
import com.google.gson.JsonObject;
|
||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||
import land.chipmunk.chipmunkmod.command.CommandManager;
|
||||
import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand;
|
||||
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
|
||||
import land.chipmunk.chipmunkmod.util.BotValidationUtilities;
|
||||
|
|
@ -38,6 +39,7 @@ public abstract class ChatScreenMixin {
|
|||
|
||||
@Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true)
|
||||
private void sendMessage (final String chatText, final boolean addToHistory, final CallbackInfo ci) {
|
||||
final CommandManager commandManager = CommandManager.INSTANCE;
|
||||
final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
if (addToHistory) {
|
||||
|
|
@ -101,6 +103,10 @@ public abstract class ChatScreenMixin {
|
|||
} catch (final Exception ignored) {
|
||||
}
|
||||
}
|
||||
} else if (chatText.startsWith(commandManager.prefix)) {
|
||||
commandManager.executeCommand(chatText.substring(commandManager.prefix.length()));
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (client.player == null) return;
|
||||
|
|
|
|||
|
|
@ -126,13 +126,6 @@ public abstract class ClientPlayNetworkHandlerMixin {
|
|||
|
||||
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
|
||||
private void sendChatMessage (final String content, final CallbackInfo ci) {
|
||||
final CommandManager commandManager = CommandManager.INSTANCE;
|
||||
if (content.startsWith(commandManager.prefix)) {
|
||||
commandManager.executeCommand(content.substring(commandManager.prefix.length()));
|
||||
ci.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (Chat.NEXT_CHAT_PLAYER.get()) {
|
||||
Chat.NEXT_CHAT_PLAYER.set(false);
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue