Skip to content

Commit

Permalink
Added options command
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 committed Mar 14, 2023
1 parent b7e1d97 commit 0179270
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
40 changes: 24 additions & 16 deletions src/main/java/com/kevinthegreat/skyblockmod/util/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
options = SkyblockMod.skyblockMod.options;
for (String key : SkyblockMod.skyblockMod.message.commands.keySet()) {
if (key.startsWith("/")) {
dispatcher.register(literal(key.substring(1)));
Expand All @@ -36,23 +40,8 @@ public void registerCommands(CommandDispatcher<FabricClientCommandSource> 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;
Expand Down Expand Up @@ -213,6 +202,7 @@ public void registerCommands(CommandDispatcher<FabricClientCommandSource> 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;
Expand Down Expand Up @@ -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<FabricClientCommandSource> 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;
}));
}
}

0 comments on commit 0179270

Please sign in to comment.