|
| 1 | +package computer.heather.advancedbackups.client; |
| 2 | + |
| 3 | +import com.mojang.brigadier.CommandDispatcher; |
| 4 | +import com.mojang.brigadier.arguments.StringArgumentType; |
| 5 | +import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
| 6 | + |
| 7 | +import computer.heather.advancedbackups.core.CoreCommandSystem; |
| 8 | +import net.minecraft.client.Minecraft; |
| 9 | +import net.minecraft.commands.CommandSourceStack; |
| 10 | +import net.minecraft.commands.Commands; |
| 11 | +import net.minecraft.network.chat.Component; |
| 12 | +import net.minecraft.network.protocol.game.ServerboundChatCommandPacket; |
| 13 | + |
| 14 | +public class AdvancedBackupsClientCommand { |
| 15 | + public static void register(CommandDispatcher<CommandSourceStack> commandDispatcher) { |
| 16 | + commandDispatcher.register(literal("backup").requires((runner) -> { |
| 17 | + return true; |
| 18 | + }).then(literal("start").executes((runner) -> { |
| 19 | + Minecraft.getInstance().player.connection.send(new ServerboundChatCommandPacket("backup start")); |
| 20 | + return 1; |
| 21 | + })) |
| 22 | + |
| 23 | + .then(literal("reload-config").executes((runner) -> { |
| 24 | + Minecraft.getInstance().player.connection.send(new ServerboundChatCommandPacket("backup reload-config")); |
| 25 | + return 1; |
| 26 | + })) |
| 27 | + |
| 28 | + .then(literal("reset-chain").executes((runner) -> { |
| 29 | + Minecraft.getInstance().player.connection.send(new ServerboundChatCommandPacket("backup reset-chain")); |
| 30 | + return 1; |
| 31 | + })) |
| 32 | + |
| 33 | + .then(literal("snapshot").executes((runner) -> { |
| 34 | + Minecraft.getInstance().player.connection.send(new ServerboundChatCommandPacket("backup snapshot")); |
| 35 | + return 1; |
| 36 | + }) |
| 37 | + |
| 38 | + .then(Commands.argument("name", StringArgumentType.greedyString()).executes((runner) -> { |
| 39 | + String name = StringArgumentType.getString(runner, "name"); |
| 40 | + Minecraft.getInstance().player.connection.send(new ServerboundChatCommandPacket("backup snapshot " + name)); |
| 41 | + return 1; |
| 42 | + }))) |
| 43 | + |
| 44 | + .then(literal("cancel").executes((runner) -> { |
| 45 | + Minecraft.getInstance().player.connection.send(new ServerboundChatCommandPacket("backup cancel")); |
| 46 | + return 1; |
| 47 | + })) |
| 48 | + |
| 49 | + .then(literal("reload-client-config").executes((runner) -> { |
| 50 | + CoreCommandSystem.reloadClientConfig((response) -> { |
| 51 | + runner.getSource().sendSuccess(() -> { |
| 52 | + return Component.literal(response); |
| 53 | + }, true); |
| 54 | + }); |
| 55 | + return 1; |
| 56 | + })) |
| 57 | + |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + //I'm no fan of having this here but it seems required |
| 62 | + public static LiteralArgumentBuilder<CommandSourceStack> literal(String literal) { |
| 63 | + return LiteralArgumentBuilder.literal(literal); |
| 64 | + } |
| 65 | + |
| 66 | + |
| 67 | +} |
0 commit comments