aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/config/SkyblockerConfigManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/config/SkyblockerConfigManager.java')
-rw-r--r--src/main/java/de/hysky/skyblocker/config/SkyblockerConfigManager.java121
1 files changed, 62 insertions, 59 deletions
diff --git a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfigManager.java b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfigManager.java
index 11a61cde..f01f463c 100644
--- a/src/main/java/de/hysky/skyblocker/config/SkyblockerConfigManager.java
+++ b/src/main/java/de/hysky/skyblocker/config/SkyblockerConfigManager.java
@@ -26,69 +26,72 @@ import java.lang.StackWalker.Option;
import java.nio.file.Path;
public class SkyblockerConfigManager {
- private static final Path PATH = FabricLoader.getInstance().getConfigDir().resolve("skyblocker-2.json");
- private static final ConfigClassHandler<SkyblockerConfig> HANDLER = ConfigClassHandler.createBuilder(SkyblockerConfig.class)
- .serializer(config -> GsonConfigSerializerBuilder.create(config)
- .setPath(PATH)
- .setJson5(false)
- .appendGsonBuilder(builder -> builder
- .setFieldNamingPolicy(FieldNamingPolicy.IDENTITY)
- .registerTypeHierarchyAdapter(Identifier.class, new Identifier.Serializer()))
- .build())
- .build();
+ private static final Path PATH = FabricLoader.getInstance().getConfigDir().resolve("skyblocker-2.json");
+ private static final ConfigClassHandler<SkyblockerConfig> HANDLER = ConfigClassHandler.createBuilder(SkyblockerConfig.class)
+ .serializer(config -> GsonConfigSerializerBuilder.create(config)
+ .setPath(PATH)
+ .setJson5(false)
+ .appendGsonBuilder(builder -> builder
+ .setFieldNamingPolicy(FieldNamingPolicy.IDENTITY)
+ .registerTypeHierarchyAdapter(Identifier.class, new Identifier.Serializer()))
+ .build())
+ .build();
- public static SkyblockerConfig get() {
- return HANDLER.instance();
- }
+ public static SkyblockerConfig get() {
+ return HANDLER.instance();
+ }
- /**
- * This method is caller sensitive and can only be called by the mod initializer,
- * this is enforced.
- */
- public static void init() {
- if (StackWalker.getInstance(Option.RETAIN_CLASS_REFERENCE).getCallerClass() != SkyblockerMod.class) {
- throw new RuntimeException("Skyblocker: Called config init from an illegal place!");
- }
+ /**
+ * This method is caller sensitive and can only be called by the mod initializer,
+ * this is enforced.
+ */
+ public static void init() {
+ if (StackWalker.getInstance(Option.RETAIN_CLASS_REFERENCE).getCallerClass() != SkyblockerMod.class) {
+ throw new RuntimeException("Skyblocker: Called config init from an illegal place!");
+ }
- HANDLER.load();
- ClientCommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal(SkyblockerMod.NAMESPACE).then(optionsLiteral("config")).then(optionsLiteral("options")))));
- ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
- if (screen instanceof GenericContainerScreen genericContainerScreen && screen.getTitle().getString().equals("SkyBlock Menu")) {
- Screens.getButtons(screen).add(ButtonWidget
- .builder(Text.literal("\uD83D\uDD27"), buttonWidget -> client.setScreen(createGUI(screen)))
- .dimensions(((HandledScreenAccessor) genericContainerScreen).getX() + ((HandledScreenAccessor) genericContainerScreen).getBackgroundWidth() - 16, ((HandledScreenAccessor) genericContainerScreen).getY() + 4, 12, 12)
- .tooltip(Tooltip.of(Text.translatable("skyblocker.title")))
- .build());
- }
- });
- }
+ HANDLER.load();
+ ClientCommandRegistrationCallback.EVENT.register(((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal(SkyblockerMod.NAMESPACE).then(optionsLiteral("config")).then(optionsLiteral("options")))));
+ ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
+ if (screen instanceof GenericContainerScreen genericContainerScreen && screen.getTitle().getString().equals("SkyBlock Menu")) {
+ Screens.getButtons(screen).add(ButtonWidget
+ .builder(Text.literal("\uD83D\uDD27"), buttonWidget -> client.setScreen(createGUI(screen)))
+ .dimensions(((HandledScreenAccessor) genericContainerScreen).getX() + ((HandledScreenAccessor) genericContainerScreen).getBackgroundWidth() - 16, ((HandledScreenAccessor) genericContainerScreen).getY() + 4, 12, 12)
+ .tooltip(Tooltip.of(Text.translatable("skyblocker.title")))
+ .build());
+ }
+ });
+ }
- public static void save() {
- HANDLER.save();
- }
+ public static void save() {
+ HANDLER.save();
+ }
- public static Screen createGUI(Screen parent) {
- return YetAnotherConfigLib.create(HANDLER, (defaults, config, builder) -> builder
- .title(Text.translatable("skyblocker.title"))
- .category(GeneralCategory.create(defaults, config))
- .category(DungeonsCategory.create(defaults, config))
- .category(DwarvenMinesCategory.create(defaults, config))
- .category(CrimsonIsleCategory.create(defaults, config))
- .category(LocationsCategory.create(defaults, config))
- .category(SlayersCategory.create(defaults, config))
- .category(QuickNavigationCategory.create(defaults, config))
- .category(MessageFilterCategory.create(defaults, config))
- .category(DiscordRPCCategory.create(defaults, config))).generateScreen(parent);
- }
+ public static Screen createGUI(Screen parent) {
+ return YetAnotherConfigLib.create(HANDLER, (defaults, config, builder) -> builder
+ .title(Text.translatable("skyblocker.title"))
+ .category(GeneralCategory.create(defaults, config))
+ .category(UIAndVisualsCategory.create(defaults, config))
+ .category(HelperCategory.create(defaults, config))
+ .category(DungeonsCategory.create(defaults, config))
+ .category(CrimsonIsleCategory.create(defaults, config))
+ .category(MiningCategory.create(defaults, config))
+ .category(FarmingCategory.create(defaults, config))
+ .category(OtherLocationsCategory.create(defaults, config))
+ .category(SlayersCategory.create(defaults, config))
+ .category(MessageFilterCategory.create(defaults, config))
+ .category(QuickNavigationCategory.create(defaults, config))
+ .category(MiscCategory.create(defaults, config))).generateScreen(parent);
+ }
- /**
- * Registers an options command with the given name. Used for registering both options and config as valid commands.
- *
- * @param name the name of the command node
- * @return the command builder
- */
- private static LiteralArgumentBuilder<FabricClientCommandSource> optionsLiteral(String name) {
- // Don't immediately open the next screen as it will be closed by ChatScreen right after this command is executed
- return ClientCommandManager.literal(name).executes(Scheduler.queueOpenScreenCommand(() -> createGUI(null)));
- }
+ /**
+ * Registers an options command with the given name. Used for registering both options and config as valid commands.
+ *
+ * @param name the name of the command node
+ * @return the command builder
+ */
+ private static LiteralArgumentBuilder<FabricClientCommandSource> optionsLiteral(String name) {
+ // Don't immediately open the next screen as it will be closed by ChatScreen right after this command is executed
+ return ClientCommandManager.literal(name).executes(Scheduler.queueOpenScreenCommand(() -> createGUI(null)));
+ }
}