mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 22:16:14 +00:00
Compare commits
No commits in common. "b613c105658d9b0ac9e82b0d7c9511a71ab39cd1" and "e13b035b10cf3b31dba73b399766aebd4249fb11" have entirely different histories.
b613c10565
...
e13b035b10
4 changed files with 8 additions and 50 deletions
|
|
@ -8,7 +8,6 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import land.chipmunk.chipmunkmod.commands.*;
|
import land.chipmunk.chipmunkmod.commands.*;
|
||||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
|
||||||
import net.minecraft.command.CommandRegistryAccess;
|
import net.minecraft.command.CommandRegistryAccess;
|
||||||
import net.minecraft.text.ClickEvent;
|
import net.minecraft.text.ClickEvent;
|
||||||
import net.minecraft.text.MutableText;
|
import net.minecraft.text.MutableText;
|
||||||
|
|
@ -38,7 +37,6 @@ public class CommandManager {
|
||||||
AutoSkinCommand.register(this.dispatcher);
|
AutoSkinCommand.register(this.dispatcher);
|
||||||
ReloadConfigCommand.register(this.dispatcher);
|
ReloadConfigCommand.register(this.dispatcher);
|
||||||
SelfCareCommand.register(this.dispatcher);
|
SelfCareCommand.register(this.dispatcher);
|
||||||
PrefixCommand.register(this.dispatcher);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LiteralArgumentBuilder<FabricClientCommandSource> literal (final String name) {
|
public static LiteralArgumentBuilder<FabricClientCommandSource> literal (final String name) {
|
||||||
|
|
@ -51,11 +49,8 @@ public class CommandManager {
|
||||||
|
|
||||||
public void executeCommand (final String command) {
|
public void executeCommand (final String command) {
|
||||||
final MinecraftClient client = MinecraftClient.getInstance();
|
final MinecraftClient client = MinecraftClient.getInstance();
|
||||||
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
|
||||||
|
|
||||||
if (networkHandler == null) return;
|
final FabricClientCommandSource commandSource = (FabricClientCommandSource) client.getNetworkHandler().getCommandSource();
|
||||||
|
|
||||||
final FabricClientCommandSource commandSource = (FabricClientCommandSource) networkHandler.getCommandSource();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dispatcher.execute(command, commandSource);
|
dispatcher.execute(command, commandSource);
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
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,7 +2,6 @@ package land.chipmunk.chipmunkmod.mixin;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||||
import land.chipmunk.chipmunkmod.command.CommandManager;
|
|
||||||
import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand;
|
import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand;
|
||||||
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
|
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
|
||||||
import land.chipmunk.chipmunkmod.util.BotValidationUtilities;
|
import land.chipmunk.chipmunkmod.util.BotValidationUtilities;
|
||||||
|
|
@ -39,7 +38,6 @@ public abstract class ChatScreenMixin {
|
||||||
|
|
||||||
@Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true)
|
||||||
private void sendMessage (final String chatText, final boolean addToHistory, final CallbackInfo ci) {
|
private void sendMessage (final String chatText, final boolean addToHistory, final CallbackInfo ci) {
|
||||||
final CommandManager commandManager = CommandManager.INSTANCE;
|
|
||||||
final MinecraftClient client = MinecraftClient.getInstance();
|
final MinecraftClient client = MinecraftClient.getInstance();
|
||||||
|
|
||||||
if (addToHistory) {
|
if (addToHistory) {
|
||||||
|
|
@ -103,10 +101,6 @@ public abstract class ChatScreenMixin {
|
||||||
} catch (final Exception ignored) {
|
} 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;
|
if (client.player == null) return;
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,13 @@ public abstract class ClientPlayNetworkHandlerMixin {
|
||||||
|
|
||||||
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
|
||||||
private void sendChatMessage (final String content, final CallbackInfo ci) {
|
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()) {
|
if (Chat.NEXT_CHAT_PLAYER.get()) {
|
||||||
Chat.NEXT_CHAT_PLAYER.set(false);
|
Chat.NEXT_CHAT_PLAYER.set(false);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue