diff --git a/README.md b/README.md index 163f357..1792161 100644 --- a/README.md +++ b/README.md @@ -12,10 +12,6 @@ Helpful features for Hypixel Skyblock ([Fabric](https://fabricmc.net/) 1.17+) - /co -> /chat officer - /cc -> /chat coop -### Config - -- /sbm config: open config screen - ### Dungeon #### Configurable dungeon map @@ -71,6 +67,10 @@ Helpful features for Hypixel Skyblock ([Fabric](https://fabricmc.net/) 1.17+) - /m [player] -> /msg [player] +### Options + +- /sbm options: open options screen + ### Quiver Low Warning - Notifies you when you only have 50 Arrows left in your Quiver @@ -129,10 +129,10 @@ Helpful features for Hypixel Skyblock ([Fabric](https://fabricmc.net/) 1.17+) ### Misc -- /sbm config reload: reload config file +- /sbm options reload: reload options file - Useful when you accidentally override a setting -- /sbm config save: manually save config file -- Config file will automatically save when you quit the game +- /sbm options save: manually save options file +- Options file will automatically save when you quit the game -Configuration file is `skyblockmod.json` located in skyblockmod folder in the config folder in the minecraft run directory +Options file is `skyblockmod.json` located in skyblockmod folder in the config folder in the minecraft run directory A backup is also saved as `skyblockmod.json_old` in the same location \ No newline at end of file diff --git a/src/main/java/com/kevinthegreat/skyblockmod/util/Commands.java b/src/main/java/com/kevinthegreat/skyblockmod/util/Commands.java index 522b39e..958d05a 100644 --- a/src/main/java/com/kevinthegreat/skyblockmod/util/Commands.java +++ b/src/main/java/com/kevinthegreat/skyblockmod/util/Commands.java @@ -8,6 +8,7 @@ import com.mojang.brigadier.arguments.DoubleArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.screen.ScreenTexts; @@ -19,7 +20,10 @@ import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; public class Commands { + private SkyblockModOptions options; + public void registerCommands(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { + options = SkyblockMod.skyblockMod.options; for (String key : SkyblockMod.skyblockMod.message.commands.keySet()) { if (key.startsWith("/")) { dispatcher.register(literal(key.substring(1))); @@ -36,23 +40,8 @@ public void registerCommands(CommandDispatcher dispat context.getSource().sendFeedback(Text.translatable("skyblockmod:reparty.repartying")); return 1; })); - SkyblockModOptions options = SkyblockMod.skyblockMod.options; dispatcher.register(literal("sbm") - .then(literal("config").executes(context -> { - // Don't immediately open the next screen as it will be closed by ChatScreen right after this command is executed - SkyblockMod.skyblockMod.setNextScreen(new SkyblockModOptionsScreen()); - return 1; - }) - .then(literal("reload").executes(context -> { - options.load(); - context.getSource().sendFeedback(Text.translatable("skyblockmod:options.reloaded")); - return 1; - })) - .then(literal("save").executes(context -> { - options.save(); - context.getSource().sendFeedback(Text.translatable("skyblockmod:options.saved")); - return 1; - }))) + .then(optionsLiteral("config")) .then(literal("dungeonMap").executes(context -> { context.getSource().sendFeedback(Text.translatable("skyblockmod:dungeonMap").append(queryOnOrOff(options.dungeonMap.getValue()))); return 1; @@ -213,6 +202,7 @@ public void registerCommands(CommandDispatcher dispat context.getSource().sendFeedback(Text.translatable("skyblockmod:lividColor").append(Text.translatable("skyblockmod:options.set")).append(ScreenTexts.onOrOff(options.lividColor.getValue())).append(": " + options.lividColorText.getValue())); return 1; })))) + .then(optionsLiteral("options")) .then(literal("quiverWarning").executes(context -> { context.getSource().sendFeedback(Text.translatable("skyblockmod:quiver").append(queryOnOrOff(options.quiver.getValue()))); return 1; @@ -240,4 +230,22 @@ private Text queryOnOrOff(boolean on) { private Text turnOnOrOff(boolean on) { return Text.translatable("skyblockmod:options.turn").append(ScreenTexts.onOrOff(on)); } + + private LiteralArgumentBuilder optionsLiteral(String name) { + return literal(name).executes(context -> { + // Don't immediately open the next screen as it will be closed by ChatScreen right after this command is executed + SkyblockMod.skyblockMod.setNextScreen(new SkyblockModOptionsScreen()); + return 1; + }) + .then(literal("reload").executes(context -> { + options.load(); + context.getSource().sendFeedback(Text.translatable("skyblockmod:options.reloaded")); + return 1; + })) + .then(literal("save").executes(context -> { + options.save(); + context.getSource().sendFeedback(Text.translatable("skyblockmod:options.saved")); + return 1; + })); + } }