From 235add4a81c1c479abe826223a178cc6d7b2a670 Mon Sep 17 00:00:00 2001 From: FabianAdrian Date: Thu, 18 Jan 2024 18:50:35 +0200 Subject: [PATCH] feature: add annotation based config sorter --- .../webhookchatlogger/common/config/ConfigManager.java | 6 +++++- .../common/config/WebhookChatLoggerConfig.java | 5 +++++ .../common/config/section/DiscordConfigSection.java | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/fi/fabianadrian/webhookchatlogger/common/config/ConfigManager.java b/common/src/main/java/fi/fabianadrian/webhookchatlogger/common/config/ConfigManager.java index ef7fccb..b9fbb3b 100644 --- a/common/src/main/java/fi/fabianadrian/webhookchatlogger/common/config/ConfigManager.java +++ b/common/src/main/java/fi/fabianadrian/webhookchatlogger/common/config/ConfigManager.java @@ -12,6 +12,7 @@ import space.arim.dazzleconf.ext.snakeyaml.SnakeYamlConfigurationFactory; import space.arim.dazzleconf.ext.snakeyaml.SnakeYamlOptions; import space.arim.dazzleconf.helper.ConfigurationHelper; +import space.arim.dazzleconf.sorter.AnnotationBasedSorter; import java.io.IOException; import java.io.UncheckedIOException; @@ -40,7 +41,10 @@ public static ConfigManager create(Path configFolder, String fileName, Cl .commentMode(CommentMode.fullComments()) .build(); - ConfigurationOptions options = new ConfigurationOptions.Builder().addSerialiser(new SimpleDateFormatSerializer()).build(); + ConfigurationOptions options = new ConfigurationOptions.Builder() + .addSerialiser(new SimpleDateFormatSerializer()) + .sorter(new AnnotationBasedSorter()) + .build(); ConfigurationFactory configFactory = SnakeYamlConfigurationFactory.create( configClass, diff --git a/common/src/main/java/fi/fabianadrian/webhookchatlogger/common/config/WebhookChatLoggerConfig.java b/common/src/main/java/fi/fabianadrian/webhookchatlogger/common/config/WebhookChatLoggerConfig.java index a14bac5..8e598bf 100644 --- a/common/src/main/java/fi/fabianadrian/webhookchatlogger/common/config/WebhookChatLoggerConfig.java +++ b/common/src/main/java/fi/fabianadrian/webhookchatlogger/common/config/WebhookChatLoggerConfig.java @@ -5,11 +5,13 @@ import space.arim.dazzleconf.annote.ConfDefault; import space.arim.dazzleconf.annote.ConfKey; import space.arim.dazzleconf.annote.SubSection; +import space.arim.dazzleconf.sorter.AnnotationBasedSorter; import java.text.SimpleDateFormat; public interface WebhookChatLoggerConfig { + @AnnotationBasedSorter.Order(0) @ConfDefault.DefaultString("[] : ") @ConfComments({ "Which format logged messages will use. Supports MiniMessage.", @@ -19,16 +21,19 @@ public interface WebhookChatLoggerConfig { }) String messageFormat(); + @AnnotationBasedSorter.Order(1) @ConfDefault.DefaultString("HH:mm:ss") @ConfComments({ "Format for the placeholder." }) SimpleDateFormat timestampFormat(); + @AnnotationBasedSorter.Order(2) @ConfDefault.DefaultBoolean(true) @ConfComments("Whether cancelled chat messages should be sent to the webhook.") boolean logCancelledMessages(); + @AnnotationBasedSorter.Order(3) @SubSection @ConfKey("discord") @ConfComments("Configuration options for the Discord client.") diff --git a/common/src/main/java/fi/fabianadrian/webhookchatlogger/common/config/section/DiscordConfigSection.java b/common/src/main/java/fi/fabianadrian/webhookchatlogger/common/config/section/DiscordConfigSection.java index 109cc14..7f1932b 100644 --- a/common/src/main/java/fi/fabianadrian/webhookchatlogger/common/config/section/DiscordConfigSection.java +++ b/common/src/main/java/fi/fabianadrian/webhookchatlogger/common/config/section/DiscordConfigSection.java @@ -2,6 +2,7 @@ import space.arim.dazzleconf.annote.ConfComments; import space.arim.dazzleconf.annote.ConfDefault; +import space.arim.dazzleconf.sorter.AnnotationBasedSorter; import java.util.HashMap; import java.util.Map; @@ -15,14 +16,17 @@ static Map defaultTextReplacements() { return replacementMap; } + @AnnotationBasedSorter.Order(0) @ConfComments("Discord webhook's ID.") @ConfDefault.DefaultString("") String id(); + @AnnotationBasedSorter.Order(1) @ConfComments("Dicsord webhook's secret token.") @ConfDefault.DefaultString("") String token(); + @AnnotationBasedSorter.Order(2) @ConfComments({ "How often to send messages (in seconds).", "Should be a value between 1 and 10.", @@ -31,6 +35,7 @@ static Map defaultTextReplacements() { @ConfDefault.DefaultInteger(5) int sendRate(); + @AnnotationBasedSorter.Order(3) @ConfDefault.DefaultObject("defaultTextReplacements") Map textReplacements(); }