diff --git a/src/client/java/dev/xdpxi/xdlib/XDsLibraryClient.java b/src/client/java/dev/xdpxi/xdlib/XDsLibraryClient.java index 3f0f96c..7e28622 100644 --- a/src/client/java/dev/xdpxi/xdlib/XDsLibraryClient.java +++ b/src/client/java/dev/xdpxi/xdlib/XDsLibraryClient.java @@ -139,7 +139,7 @@ public void onInitializeClient() { configServerName = clientSettings.configServerName; configServerAddress = clientSettings.configServerAddress; } - LOGGER.info("[XDLib] - Applying Config..."); + LOGGER.info("[XDLib] - Applying config..."); if (discordRPC) { if (osName.contains("win")) { DiscordRPCHandler.init(); @@ -153,7 +153,7 @@ public void onInitializeClient() { if (sodiumIntegration) { CustomOptions.integrate(); } - LOGGER.info("[XDLib] - Applied Config!"); + LOGGER.info("[XDLib] - Applied config!"); if (clothConfig) { configHelper.registerSaveListener(discordRPC, sodiumIntegration); diff --git a/src/client/java/dev/xdpxi/xdlib/api/config.java b/src/client/java/dev/xdpxi/xdlib/api/config.java index 05066e2..20f61aa 100644 --- a/src/client/java/dev/xdpxi/xdlib/api/config.java +++ b/src/client/java/dev/xdpxi/xdlib/api/config.java @@ -10,6 +10,7 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.lang.reflect.ParameterizedType; import java.util.HashMap; import java.util.Map; @@ -67,10 +68,11 @@ public void loadConfig() { try (FileReader reader = new FileReader(CONFIG_FILE)) { switch (fileType) { case TOML: - configInstance = (T) new Toml().read(reader).to(configInstance.getClass()); + Toml toml = new Toml(); + configInstance = (T) toml.read(reader).to(configInstance.getClass()); break; case JSON: - configInstance = GSON.fromJson(reader, (Class) configInstance.getClass()); + configInstance = GSON.fromJson(reader, (Class) getGenericType()); break; } } catch (IOException ignored) { @@ -82,5 +84,9 @@ public T getConfig() { return configInstance; } + private Class getGenericType() { + return (Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]; + } + private enum FileType {JSON, TOML} } \ No newline at end of file diff --git a/src/client/java/dev/xdpxi/xdlib/api/configClass/modmenu.java b/src/client/java/dev/xdpxi/xdlib/api/configClass/modmenu.java index 7e87825..17d1314 100644 --- a/src/client/java/dev/xdpxi/xdlib/api/configClass/modmenu.java +++ b/src/client/java/dev/xdpxi/xdlib/api/configClass/modmenu.java @@ -29,17 +29,17 @@ private Screen createConfigScreen(Screen parent, config public void init() { int yOffset = this.height / 6 + 24; - this.addDrawableChild(ButtonWidget.builder(Text.of("Save Config"), (button) -> { + this.addDrawableChild(ButtonWidget.builder(Text.of("Save config"), (button) -> { config.saveConfig(); this.client.getToastManager().add( - SystemToast.create(this.client, SystemToast.Type.WORLD_BACKUP, Text.of("Config Saved!"), null) + SystemToast.create(this.client, SystemToast.Type.WORLD_BACKUP, Text.of("config Saved!"), null) ); }).dimensions(this.width / 2 - 100, yOffset, 200, 20).build()); - this.addDrawableChild(ButtonWidget.builder(Text.of("Reset Config"), (button) -> { + this.addDrawableChild(ButtonWidget.builder(Text.of("Reset config"), (button) -> { config.loadConfig(); // Assuming loadConfig resets it this.client.getToastManager().add( - SystemToast.create(this.client, SystemToast.Type.WORLD_BACKUP, Text.of("Config Reset!"), null) + SystemToast.create(this.client, SystemToast.Type.WORLD_BACKUP, Text.of("config Reset!"), null) ); }).dimensions(this.width / 2 - 100, yOffset + 25, 200, 20).build());