diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/config/main/BukkitConfig.java b/bukkit/src/main/java/com/discordsrv/bukkit/config/main/BukkitConfig.java index e62e9a8d..90c7716b 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/config/main/BukkitConfig.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/config/main/BukkitConfig.java @@ -19,6 +19,7 @@ package com.discordsrv.bukkit.config.main; import com.discordsrv.api.channel.GameChannel; +import com.discordsrv.common.config.annotation.Order; import com.discordsrv.common.config.main.MainConfig; import com.discordsrv.common.config.main.PluginIntegrationConfig; import com.discordsrv.common.config.main.channels.base.ChannelConfig; @@ -35,8 +36,10 @@ public class BukkitConfig extends MainConfig { channels.put(ChannelConfig.DEFAULT_KEY, new ServerBaseChannelConfig()); } + @Order(5) public BukkitRequiredLinkingConfig requiredLinking = new BukkitRequiredLinkingConfig(); + @Order(100) public PluginIntegrationConfig integrations = new PluginIntegrationConfig(); @Override diff --git a/common/src/main/java/com/discordsrv/common/component/renderer/DiscordSRVMinecraftRenderer.java b/common/src/main/java/com/discordsrv/common/component/renderer/DiscordSRVMinecraftRenderer.java index 6d667489..48fd46e3 100644 --- a/common/src/main/java/com/discordsrv/common/component/renderer/DiscordSRVMinecraftRenderer.java +++ b/common/src/main/java/com/discordsrv/common/component/renderer/DiscordSRVMinecraftRenderer.java @@ -84,7 +84,7 @@ public class DiscordSRVMinecraftRenderer extends DefaultMinecraftRenderer { GuildChannel guildChannel = jda.getGuildChannelById(channel); Context context = CONTEXT.get(); - String format = context != null ? context.config.map(cfg -> cfg.mentions).get(cfg -> cfg.message) : null; + String format = context != null ? context.config.map(cfg -> cfg.mentions).get(cfg -> cfg.messageUrl) : null; if (format == null || guildChannel == null) { return super.appendLink(part, link); } diff --git a/common/src/main/java/com/discordsrv/common/config/connection/MinecraftAuthConfig.java b/common/src/main/java/com/discordsrv/common/config/connection/MinecraftAuthConfig.java index 52c430d1..a87d9b7d 100644 --- a/common/src/main/java/com/discordsrv/common/config/connection/MinecraftAuthConfig.java +++ b/common/src/main/java/com/discordsrv/common/config/connection/MinecraftAuthConfig.java @@ -24,7 +24,7 @@ import org.spongepowered.configurate.objectmapping.meta.Comment; @ConfigSerializable public class MinecraftAuthConfig { - @Comment("If minecraftauth.me connections are allowed for Discord linking (requires linked-accounts.provider to be \"auto\" or \"minecraftauth\").\n" + @Comment("If minecraftauth.me connections are allowed for Discord linking (when linked-accounts.provider is \"auto\" or \"minecraftauth\").\n" + "Requires a connection to: minecraftauth.me\n" + "Privacy Policy: https://minecraftauth.me/privacy") public boolean allow = true; diff --git a/common/src/main/java/com/discordsrv/common/config/connection/StorageConfig.java b/common/src/main/java/com/discordsrv/common/config/connection/StorageConfig.java index 1b324680..57e7fbb1 100644 --- a/common/src/main/java/com/discordsrv/common/config/connection/StorageConfig.java +++ b/common/src/main/java/com/discordsrv/common/config/connection/StorageConfig.java @@ -30,8 +30,8 @@ public class StorageConfig { @Comment("The storage backend to use.\n\n" + "- H2\n" - + "- MySQL\n") - public String backend = "h2"; + + "- MySQL") + public String backend = "H2"; @Comment("SQL table prefix") public String sqlTablePrefix = "discordsrv_"; diff --git a/common/src/main/java/com/discordsrv/common/config/main/channels/DiscordToMinecraftChatConfig.java b/common/src/main/java/com/discordsrv/common/config/main/channels/DiscordToMinecraftChatConfig.java index 2af2a151..fae209a7 100644 --- a/common/src/main/java/com/discordsrv/common/config/main/channels/DiscordToMinecraftChatConfig.java +++ b/common/src/main/java/com/discordsrv/common/config/main/channels/DiscordToMinecraftChatConfig.java @@ -63,7 +63,7 @@ public class DiscordToMinecraftChatConfig { public Format channel = new Format("[hover:show_text:Click to go to channel][click:open_url:%channel_jump_url%]ᛩf2#%channel_name%", "ᛩf2#deleted-channel"); public Format user = new Format("[hover:show_text:Tag: %user_tag%&r\nRoles: %user_roles_, |text_&7&oNone%]ᛩf2@%user_effective_name|user_name%", "ᛩf2@Unknown user"); - public String message = "[hover:show_text:Click to go to message][click:open_url:%jump_url%]ᛩf2#%channel_name% > ..."; + public String messageUrl = "[hover:show_text:Click to go to message][click:open_url:%jump_url%]ᛩf2#%channel_name% > ..."; @ConfigSerializable public static class Format { diff --git a/common/src/main/java/com/discordsrv/common/config/manager/manager/ConfigurateConfigManager.java b/common/src/main/java/com/discordsrv/common/config/manager/manager/ConfigurateConfigManager.java index cf8365ae..dd38010b 100644 --- a/common/src/main/java/com/discordsrv/common/config/manager/manager/ConfigurateConfigManager.java +++ b/common/src/main/java/com/discordsrv/common/config/manager/manager/ConfigurateConfigManager.java @@ -35,18 +35,21 @@ import com.discordsrv.common.config.serializer.PatternSerializer; import com.discordsrv.common.config.serializer.SendableDiscordMessageSerializer; import com.discordsrv.common.exception.ConfigException; import org.jetbrains.annotations.Nullable; -import org.spongepowered.configurate.CommentedConfigurationNode; -import org.spongepowered.configurate.ConfigurateException; -import org.spongepowered.configurate.ConfigurationNode; -import org.spongepowered.configurate.ConfigurationOptions; +import org.spongepowered.configurate.*; import org.spongepowered.configurate.loader.AbstractConfigurationLoader; import org.spongepowered.configurate.objectmapping.ConfigSerializable; import org.spongepowered.configurate.objectmapping.FieldDiscoverer; import org.spongepowered.configurate.objectmapping.ObjectMapper; +import org.spongepowered.configurate.objectmapping.meta.Comment; +import org.spongepowered.configurate.objectmapping.meta.Processor; import org.spongepowered.configurate.serialize.SerializationException; +import org.spongepowered.configurate.serialize.TypeSerializer; import org.spongepowered.configurate.util.NamingScheme; import org.spongepowered.configurate.util.NamingSchemes; +import org.spongepowered.configurate.yaml.ScalarStyle; +import org.spongepowered.configurate.yaml.YamlConfigurationLoader; +import java.lang.reflect.Type; import java.nio.file.Path; import java.util.Arrays; import java.util.Comparator; @@ -103,6 +106,26 @@ public abstract class ConfigurateConfigManager { + builder.register(String.class, new TypeSerializer() { + + @Override + public String deserialize(Type type, ConfigurationNode node) { + return node.getString(); + } + + @Override + public void serialize(Type type, @org.checkerframework.checker.nullness.qual.Nullable String obj, ConfigurationNode node) { + RepresentationHint hint = YamlConfigurationLoader.SCALAR_STYLE; + + ScalarStyle style = node.hint(hint); + if (style == hint.defaultValue()) { + // Set scalar style for strings to double quotes, by default + node = node.hint(hint, ScalarStyle.DOUBLE_QUOTED); + } + + node.raw(obj); + } + }); builder.register(BaseChannelConfig.class, getChannelConfigSerializer(objectMapper)); builder.register(Color.class, new ColorSerializer()); builder.register(Pattern.class, new PatternSerializer()); @@ -136,6 +159,20 @@ public abstract class ConfigurateConfigManager { + Processor processor = Processor.comments().make(data, fieldType); + + return (value, destination) -> { + processor.process(value, destination); + if (destination instanceof CommentedConfigurationNode) { + String comment = ((CommentedConfigurationNode) destination).comment(); + if (comment != null) { + // Yaml doesn't render empty lines correctly, so we add a space when there are double line breaks + ((CommentedConfigurationNode) destination).comment(comment.replace("\n\n", "\n \n")); + } + } + }; + }) .defaultNamingScheme(NAMING_SCHEME) .addDiscoverer(new OrderedFieldDiscovererProxy<>((FieldDiscoverer) FieldDiscoverer.emptyConstructorObject(), fieldOrder)) .addDiscoverer(new OrderedFieldDiscovererProxy<>((FieldDiscoverer) FieldDiscoverer.record(), fieldOrder));