Skip to content

Commit

Permalink
Move metrics config node.
Browse files Browse the repository at this point in the history
  • Loading branch information
RezzedUp committed Dec 17, 2022
1 parent 42ed1c4 commit c9662fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions src/main/java/community/leaf/survival/concretemixer/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -32,7 +32,10 @@ public class Config extends YamlDataFile
.maybe();

public static final DefaultYamlValue<Boolean> 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"
Expand Down Expand Up @@ -113,6 +116,8 @@ public Config(ConcreteMixerPlugin plugin)

if (isUpdated())
{
removeEmptyConfigurationSections(data());

if (outdated)
{
if (existing.greaterThan(Versions.ZERO))
Expand All @@ -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); }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public int totalTransformationsInTheLastHour()
{
Map.Entry<Instant, Integer> 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(); }
}

Expand Down

0 comments on commit c9662fc

Please sign in to comment.