From c9662fc9e1dd2e01df8e03be84b46827b833eb0b Mon Sep 17 00:00:00 2001 From: RezzedUp Date: Fri, 16 Dec 2022 23:59:47 -0600 Subject: [PATCH] Move metrics config node. --- .../leaf/survival/concretemixer/Config.java | 25 ++++++++++++++++--- .../metrics/TransformationsPerHour.java | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/community/leaf/survival/concretemixer/Config.java b/src/main/java/community/leaf/survival/concretemixer/Config.java index e5a39f1..502558d 100644 --- a/src/main/java/community/leaf/survival/concretemixer/Config.java +++ b/src/main/java/community/leaf/survival/concretemixer/Config.java @@ -10,17 +10,17 @@ import com.github.zafarkhaja.semver.Version; import com.rezzedup.util.constants.Aggregates; import com.rezzedup.util.constants.annotations.AggregatedResult; -import com.rezzedup.util.valuables.Adapter; import community.leaf.configvalues.bukkit.DefaultYamlValue; -import community.leaf.configvalues.bukkit.YamlAccessor; import community.leaf.configvalues.bukkit.YamlValue; import community.leaf.configvalues.bukkit.data.Load; import community.leaf.configvalues.bukkit.data.YamlDataFile; +import community.leaf.configvalues.bukkit.migrations.Migration; import community.leaf.survival.concretemixer.util.Versions; import org.bukkit.Sound; +import org.bukkit.configuration.ConfigurationSection; +import pl.tlinkowski.annotation.basic.NullOr; import java.util.List; -import java.util.Optional; public class Config extends YamlDataFile { @@ -32,7 +32,10 @@ public class Config extends YamlDataFile .maybe(); public static final DefaultYamlValue METRICS = - YamlValue.ofBoolean("metrics.enabled") + YamlValue.ofBoolean("plugin.metrics") + .migrates( + Migration.move("metrics.enabled") + ) .comments( "May we collect anonymous usage metrics?", "https://bstats.org/plugin/bukkit/ConcreteMixer/15590" @@ -113,6 +116,8 @@ public Config(ConcreteMixerPlugin plugin) if (isUpdated()) { + removeEmptyConfigurationSections(data()); + if (outdated) { if (existing.greaterThan(Versions.ZERO)) @@ -134,4 +139,16 @@ public Config(ConcreteMixerPlugin plugin) } }); } + + private void removeEmptyConfigurationSections(ConfigurationSection section) + { + for (String key : section.getKeys(false)) + { + @NullOr ConfigurationSection child = section.getConfigurationSection(key); + if (child == null) { continue; } + + removeEmptyConfigurationSections(child); + if (child.getKeys(false).isEmpty()) { section.set(key, null); } + } + } } diff --git a/src/main/java/community/leaf/survival/concretemixer/metrics/TransformationsPerHour.java b/src/main/java/community/leaf/survival/concretemixer/metrics/TransformationsPerHour.java index e2f3bbc..d60ff09 100644 --- a/src/main/java/community/leaf/survival/concretemixer/metrics/TransformationsPerHour.java +++ b/src/main/java/community/leaf/survival/concretemixer/metrics/TransformationsPerHour.java @@ -46,7 +46,7 @@ public int totalTransformationsInTheLastHour() { Map.Entry entry = it.next(); - if (ChronoUnit.MINUTES.between(entry.getKey(), now) >= 60) { it.remove(); } + if (ChronoUnit.MINUTES.between(entry.getKey(), now) > 60) { it.remove(); } else { total += entry.getValue(); } }