mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 18:46:15 +00:00
feat: PrefixCommand
This commit is contained in:
parent
cf428682a2
commit
b613c10565
2 changed files with 44 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ 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;
|
||||||
|
|
@ -37,6 +38,7 @@ 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) {
|
||||||
|
|
@ -49,8 +51,11 @@ 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();
|
||||||
|
|
||||||
final FabricClientCommandSource commandSource = (FabricClientCommandSource) client.getNetworkHandler().getCommandSource();
|
if (networkHandler == null) return;
|
||||||
|
|
||||||
|
final FabricClientCommandSource commandSource = (FabricClientCommandSource) networkHandler.getCommandSource();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dispatcher.execute(command, commandSource);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue