blob: 60e6b52977090b608de999011d0ef66fd3998c6c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package com.arslaancodes.arslaansmagichax.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.network.chat.Component;
import com.arslaancodes.arslaansmagichax.modules.ModuleManager;
public class ModuleToggleCommand {
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandBuildContext access) {
dispatcher.register(
ClientCommandManager.literal("module")
.then(
ClientCommandManager.literal("toggle")
.then(
ClientCommandManager.argument("moduleName", StringArgumentType.word())
.suggests(new ModuleSuggestionProvider())
.executes(ModuleToggleCommand::run)
)
)
);
}
private static int run(CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException {
String moduleName = StringArgumentType.getString(context, "moduleName");
ModuleManager.getAllModules().stream()
.filter(m -> m.getName().equalsIgnoreCase(moduleName))
.findFirst()
.ifPresentOrElse(module -> {
module.toggle();
context.getSource().sendFeedback(Component.literal(
"Toggled module " + module.getName() + " to " + (module.isEnabled() ? "ON" : "OFF")
));
}, () -> context.getSource().sendError(Component.literal("Module not found: " + moduleName)));
return 1;
}
}
|