|
8 | 8 | import dev.dfonline.codeclient.action.Action; |
9 | 9 | import dev.dfonline.codeclient.action.None; |
10 | 10 | import dev.dfonline.codeclient.action.impl.*; |
| 11 | +import dev.dfonline.codeclient.config.Config; |
11 | 12 | import dev.dfonline.codeclient.dev.Debug.Debug; |
12 | 13 | import dev.dfonline.codeclient.hypercube.template.Template; |
13 | 14 | import dev.dfonline.codeclient.location.Dev; |
|
16 | 17 | import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; |
17 | 18 | import net.minecraft.block.entity.SignText; |
18 | 19 | import net.minecraft.client.font.TextRenderer; |
| 20 | +import net.minecraft.client.gui.screen.Screen; |
19 | 21 | import net.minecraft.item.ItemStack; |
20 | 22 | import net.minecraft.text.ClickEvent; |
21 | 23 | import net.minecraft.text.HoverEvent; |
|
34 | 36 | import java.util.regex.Pattern; |
35 | 37 |
|
36 | 38 | import static com.mojang.brigadier.arguments.StringArgumentType.greedyString; |
| 39 | +import static com.mojang.brigadier.arguments.StringArgumentType.string; |
37 | 40 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; |
38 | 41 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; |
39 | 42 |
|
40 | 43 | public class Commands { |
41 | 44 | private static final Text DONE = Text.translatable("gui.done"); |
42 | 45 | public static Action confirm = null; |
| 46 | + public static Screen screen = null; |
43 | 47 |
|
44 | 48 | private static void actionCallback() { |
45 | 49 | CodeClient.currentAction = new None(); |
46 | 50 | Utility.sendMessage(DONE, ChatType.SUCCESS); |
47 | 51 | } |
48 | 52 |
|
| 53 | + public static void tick() { |
| 54 | + if(screen != null) { |
| 55 | + CodeClient.MC.setScreen(screen); |
| 56 | + screen = null; |
| 57 | + } |
| 58 | + } |
| 59 | + |
49 | 60 | public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) { |
| 61 | + dispatcher.register(literal("ccconfig").executes(context -> { |
| 62 | + screen = Config.getConfig().getLibConfig().generateScreen(null); |
| 63 | + return 0; |
| 64 | + }).then(argument("option", string()).suggests((context, builder) -> { |
| 65 | + var option = builder.getRemaining(); |
| 66 | + for (var field : Config.class.getFields()) { |
| 67 | + if(field.getName().toLowerCase().startsWith(option.toLowerCase())) builder.suggest(field.getName()); |
| 68 | + } |
| 69 | + return builder.buildFuture(); |
| 70 | + }).executes(context -> { |
| 71 | + var option = context.getArgument("option",String.class); |
| 72 | + try { |
| 73 | + Utility.sendMessage( |
| 74 | + Text.translatable("codeclient.config.command.query", |
| 75 | + Text.literal(option).formatted(Formatting.AQUA), |
| 76 | + Text.literal(String.valueOf(Config.class.getField(option).get(Config.getConfig()))).formatted(Formatting.AQUA))); |
| 77 | + } catch (Exception e) { |
| 78 | + Utility.sendMessage(Text.translatable("codeclient.config.command.query.fail",Text.literal(option).formatted(Formatting.YELLOW)),ChatType.FAIL); |
| 79 | + } |
| 80 | + return 0; |
| 81 | + }).then(argument("value",greedyString()).suggests((context, builder) -> { |
| 82 | + var option = context.getArgument("option",String.class); |
| 83 | + try { |
| 84 | + var value = builder.getRemaining(); |
| 85 | + var field = Config.class.getField(option); |
| 86 | + List<String> options; |
| 87 | + if(field.getType().equals(boolean.class)) { |
| 88 | + options = List.of("true","false"); |
| 89 | + } |
| 90 | + else if(field.getType().isEnum()) { |
| 91 | + options = new ArrayList<>(); |
| 92 | + for(Object member : field.getType().getEnumConstants()) { |
| 93 | + options.add(((Enum<?>) member).name()); |
| 94 | + } |
| 95 | + } |
| 96 | + else options = List.of(); |
| 97 | + for (var possibility : options) { |
| 98 | + if(possibility.toLowerCase().startsWith(value.toLowerCase())) builder.suggest(possibility); |
| 99 | + } |
| 100 | + } catch (Exception ignored) {} |
| 101 | + return builder.buildFuture(); |
| 102 | + }).executes(context -> { |
| 103 | + var option = context.getArgument("option",String.class); |
| 104 | + try { |
| 105 | + var value = context.getArgument("value",String.class); |
| 106 | + var field = Config.class.getField(option); |
| 107 | + if(field.getType().equals(boolean.class)) { |
| 108 | + var bool = Boolean.valueOf(value); |
| 109 | + field.set(Config.getConfig(),bool); |
| 110 | + Utility.sendMessage(Text.translatable(bool ? "codeclient.config.command.enable" : "codeclient.config.command.disable",Text.literal(option).formatted(Formatting.AQUA)),ChatType.SUCCESS); |
| 111 | + Config.getConfig().save(); |
| 112 | + } |
| 113 | + else if(field.getType().isEnum()) { |
| 114 | + for(Object member : field.getType().getEnumConstants()) { |
| 115 | + if(((Enum<?>) member).name().equalsIgnoreCase(value)) { |
| 116 | + field.set(Config.getConfig(),member); |
| 117 | + Utility.sendMessage(Text.translatable("codeclient.config.command.enum",Text.literal(option).formatted(Formatting.AQUA),Text.literal(value).formatted(Formatting.AQUA)),ChatType.SUCCESS); |
| 118 | + Config.getConfig().save(); |
| 119 | + return 0; |
| 120 | + } |
| 121 | + } |
| 122 | + Utility.sendMessage(Text.translatable("codeclient.config.command.enum.fail",Text.literal(option).formatted(Formatting.YELLOW),Text.literal(value).formatted(Formatting.YELLOW)),ChatType.FAIL); |
| 123 | + return -1; |
| 124 | + } |
| 125 | + Utility.sendMessage(Text.translatable("codeclient.config.command.fail"),ChatType.FAIL); |
| 126 | + } catch (Exception ignored) {} |
| 127 | + return 0; |
| 128 | + })))); |
| 129 | + |
50 | 130 | dispatcher.register(literal("auth").executes(context -> { |
51 | 131 | SocketHandler.setAuthorised(true); |
52 | 132 | Utility.sendMessage(Text.translatable("codeclient.api.authorised") |
|
0 commit comments