diff --git a/src/main/java/cc/fascinated/wildaddons/Main.java b/src/main/java/cc/fascinated/wildaddons/Main.java index 6fb80c2..1246054 100644 --- a/src/main/java/cc/fascinated/wildaddons/Main.java +++ b/src/main/java/cc/fascinated/wildaddons/Main.java @@ -27,7 +27,7 @@ public class Main implements ModInitializer { @Getter private static final Config statisticsConfig; static { String dirName = minecraftClient.runDirectory.getAbsolutePath() + File.separator + "wildaddons"; - statisticsConfig = new Config(dirName, "statistics.conf"); + statisticsConfig = new Config(dirName, "statistics.json"); } /** diff --git a/src/main/java/cc/fascinated/wildaddons/addon/impl/ui/OverlayAddon.java b/src/main/java/cc/fascinated/wildaddons/addon/impl/ui/OverlayAddon.java index 02003a7..973124d 100644 --- a/src/main/java/cc/fascinated/wildaddons/addon/impl/ui/OverlayAddon.java +++ b/src/main/java/cc/fascinated/wildaddons/addon/impl/ui/OverlayAddon.java @@ -2,6 +2,7 @@ package cc.fascinated.wildaddons.addon.impl.ui; import cc.fascinated.wildaddons.Main; import cc.fascinated.wildaddons.addon.Addon; +import cc.fascinated.wildaddons.statistic.Statistic; import cc.fascinated.wildaddons.tpsmonitor.TpsMonitor; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.minecraft.client.MinecraftClient; @@ -24,6 +25,13 @@ public class OverlayAddon extends Addon { TextRenderer renderer = minecraftClient.textRenderer; renderer.drawWithShadow(matrixStack, "FPS: " + minecraftClient.getCurrentFps(), 5, 5, 0xffffff); renderer.drawWithShadow(matrixStack, "TPS: " + TpsMonitor.getFormattedTPS(), 5, 16, 0xffffff); + + renderer.drawWithShadow(matrixStack, "Statistics:", 5, 30, 0xffffff); + int lastY = 41; + for (Statistic statistic : Statistic.values()) { + renderer.drawWithShadow(matrixStack, statistic.name() + " - " + statistic.get(), 5, lastY, 0xffffff); + lastY += 11; + } }); } } diff --git a/src/main/java/cc/fascinated/wildaddons/statistic/Statistic.java b/src/main/java/cc/fascinated/wildaddons/statistic/Statistic.java index d0d1793..10776bf 100644 --- a/src/main/java/cc/fascinated/wildaddons/statistic/Statistic.java +++ b/src/main/java/cc/fascinated/wildaddons/statistic/Statistic.java @@ -8,10 +8,7 @@ import org.spongepowered.configurate.ConfigurateException; import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.serialize.SerializationException; -import java.util.HashMap; -import java.util.List; -import java.util.Timer; -import java.util.TimerTask; +import java.util.*; @Getter @RequiredArgsConstructor public enum Statistic { @@ -95,26 +92,14 @@ public enum Statistic { * @param node the configuration node to load from */ public static void loadStatistics(ConfigurationNode node) { - try { - List keys = node.getList(String.class); - if (keys == null) { - return; - } - for (String key : keys) { - ConfigurationNode keyNode = node.node(key); - if (keyNode == null) { - continue; - } - Integer value = keyNode.get(Integer.class, 0); - if (value == null) { - continue; - } - statistics.put(Statistic.FILTERED_MESSAGES.getStatisticFromKey(key), value); - } + for (Map.Entry entry : node.childrenMap().entrySet()) { + ConfigurationNode data = entry.getValue(); + String key = (String) data.key(); + int value = data.getInt(); - } catch (SerializationException e) { - throw new RuntimeException(e); + statistics.put(Statistic.getStatisticFromKey(key), value); } + Main.LOGGER.info("Loaded statistics."); } /** @@ -123,7 +108,7 @@ public enum Statistic { * @param key the key to check against * @return the statistic if found, otherwise null */ - public Statistic getStatisticFromKey(String key) { + public static Statistic getStatisticFromKey(String key) { for (Statistic value : values()) { if (value.key.equalsIgnoreCase(key)) { return value; diff --git a/src/main/java/cc/fascinated/wildaddons/utils/Config.java b/src/main/java/cc/fascinated/wildaddons/utils/Config.java index b7aa5ac..b9d19e5 100644 --- a/src/main/java/cc/fascinated/wildaddons/utils/Config.java +++ b/src/main/java/cc/fascinated/wildaddons/utils/Config.java @@ -37,8 +37,17 @@ public class Config { } } - configurationLoader = HoconConfigurationLoader.builder().file(file).prettyPrinting(true).build(); - node = configurationLoader.createNode(ConfigurationOptions.defaults()); + configurationLoader = HoconConfigurationLoader.builder() + .file(file) + .emitJsonCompatible(true) + .emitComments(true) + .prettyPrinting(true) + .build(); + try { + node = configurationLoader.load(); + } catch (ConfigurateException e) { + throw new RuntimeException(e); + } } /**