mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-12-26 17:18:29 +01:00
Config improvements
This commit is contained in:
parent
bded7cc26d
commit
7314fdb72b
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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_";
|
||||
|
@ -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 {
|
||||
|
@ -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<T, LT extends AbstractConfigurati
|
||||
.shouldCopyDefaults(false)
|
||||
.implicitInitialization(false)
|
||||
.serializers(builder -> {
|
||||
builder.register(String.class, new TypeSerializer<String>() {
|
||||
|
||||
@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<ScalarStyle> 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<T, LT extends AbstractConfigurati
|
||||
});
|
||||
|
||||
return ObjectMapper.factoryBuilder()
|
||||
.addProcessor(Comment.class, (data, fieldType) -> {
|
||||
Processor<Object> 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<Object>) FieldDiscoverer.emptyConstructorObject(), fieldOrder))
|
||||
.addDiscoverer(new OrderedFieldDiscovererProxy<>((FieldDiscoverer<Object>) FieldDiscoverer.record(), fieldOrder));
|
||||
|
Loading…
Reference in New Issue
Block a user