mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-02-17 01:51:32 +01:00
Some config improvements
This commit is contained in:
parent
3b7701ee1a
commit
cd12530675
@ -12,7 +12,8 @@ import java.lang.annotation.RetentionPolicy;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Constants {
|
||||
|
||||
String[] value();
|
||||
String[] value() default {};
|
||||
int[] intValue() default {};
|
||||
|
||||
/**
|
||||
* Needs to go after {@link org.spongepowered.configurate.objectmapping.meta.Comment}.
|
||||
@ -20,6 +21,7 @@ public @interface Constants {
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Comment {
|
||||
|
||||
String[] value();
|
||||
String[] value() default {};
|
||||
int[] intValue() default {};
|
||||
}
|
||||
}
|
||||
|
@ -53,10 +53,7 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class ConfigurateConfigManager<T, LT extends AbstractConfigurationLoader<CommentedConfigurationNode>>
|
||||
@ -218,13 +215,14 @@ public abstract class ConfigurateConfigManager<T, LT extends AbstractConfigurati
|
||||
String comment = ((CommentedConfigurationNode) destination).comment();
|
||||
if (comment != null) {
|
||||
((CommentedConfigurationNode) destination).comment(
|
||||
doSubstitution(comment, data.value())
|
||||
doSubstitution(comment, getValues(data.value(), data.intValue()))
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
.addProcessor(Constants.class, (data, fieldType) -> (value, destination) -> {
|
||||
if (data == null || data.value().length == 0) {
|
||||
String[] values = getValues(data.value(), data.intValue());
|
||||
if (values.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -234,18 +232,21 @@ public abstract class ConfigurateConfigManager<T, LT extends AbstractConfigurati
|
||||
}
|
||||
|
||||
try {
|
||||
destination.set(
|
||||
doSubstitution(
|
||||
destination.getString(),
|
||||
data.value()
|
||||
)
|
||||
);
|
||||
destination.set(doSubstitution(destination.getString(), values));
|
||||
} catch (SerializationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String[] getValues(String[] value, int[] intValue) {
|
||||
List<String> values = new ArrayList<>(Arrays.asList(value));
|
||||
for (int i : intValue) {
|
||||
values.add(String.valueOf(i));
|
||||
}
|
||||
return values.toArray(new String[0]);
|
||||
}
|
||||
|
||||
private static String doSubstitution(String input, String[] values) {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
input = input.replace("%" + (i + 1), values[i]);
|
||||
|
@ -28,12 +28,12 @@ public class ConnectionConfig implements Config {
|
||||
|
||||
public static final String FILE_NAME = "connections.yaml";
|
||||
|
||||
@Constants(MainConfig.FILE_NAME)
|
||||
@Constants({MainConfig.FILE_NAME, "443", "https/wss"})
|
||||
public static final String HEADER = "DiscordSRV's configuration file for connections to different external services.\n"
|
||||
+ "This file is intended to contain connection details to services in order to keep them out of the %1\n"
|
||||
+ "and to serve as a easy way to identify and control what external connections are being used.\n"
|
||||
+ "\n"
|
||||
+ "All domains listed as \"Requires a connection to\" require port 443 (https/wss) unless otherwise specified\n"
|
||||
+ "All domains listed as \"Requires a connection to\" require port %2 (%3) unless otherwise specified\n"
|
||||
+ "\n"
|
||||
+ " ABSOLUTELY DO NOT SEND THIS FILE TO ANYONE - IT ONLY CONTAINS SECRETS\n";
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.discordsrv.common.config.main;
|
||||
|
||||
import com.discordsrv.common.config.configurate.annotation.Constants;
|
||||
import com.discordsrv.common.config.configurate.annotation.Untranslated;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
@ -12,8 +13,9 @@ public class AvatarProviderConfig {
|
||||
public boolean autoDecideAvatarUrl = true;
|
||||
|
||||
@Untranslated(Untranslated.Type.VALUE)
|
||||
@Constants("auto-decide-avatar-url")
|
||||
@Comment("The template for URLs of player avatars\n" +
|
||||
"This will be used for official Java players only if auto-decide-avatar-url is set to true\n" +
|
||||
"This will be used ALWAYS if auto-decide-avatar-url is set to false")
|
||||
"This will be used for official Java players only if %1 is set to true\n" +
|
||||
"This will be used ALWAYS if %1 is set to false")
|
||||
public String avatarUrlTemplate = "https://crafatar.com/avatars/%player_uuid_short%.png?size=128&overlay#%player_skin_texture_id%";
|
||||
}
|
||||
|
@ -5,7 +5,10 @@ import com.discordsrv.common.config.main.generic.GameCommandExecutionConditionCo
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@ConfigSerializable
|
||||
public class ConsoleConfig {
|
||||
|
@ -33,12 +33,11 @@ public class DiscordCommandConfig {
|
||||
public boolean ephemeral = true;
|
||||
|
||||
@Comment("The mode for the command output, available options are:\n"
|
||||
+ "- %1: Regular Discord markdown\n"
|
||||
+ "- %2: A colored ansi code block\n"
|
||||
+ "- %3: Plain text\n"
|
||||
+ "- %4: Plain code block\n"
|
||||
+ "- %5: No command output")
|
||||
@Constants.Comment({"markdown", "ansi", "plain", "code_block", "off"})
|
||||
+ "- markdown: Regular Discord markdown\n"
|
||||
+ "- ansi: A colored ansi code block\n"
|
||||
+ "- plain: Plain text\n"
|
||||
+ "- code_block: Plain code block\n"
|
||||
+ "- off: No command output")
|
||||
public OutputMode outputMode = OutputMode.MARKDOWN;
|
||||
|
||||
@Comment("At least one condition has to match to allow execution")
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.discordsrv.common.config.main;
|
||||
|
||||
import com.discordsrv.common.config.configurate.annotation.Constants;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
|
||||
@ -49,6 +50,8 @@ public class TimedUpdaterConfig {
|
||||
|
||||
public static class VoiceChannelConfig implements UpdaterConfig {
|
||||
|
||||
private static final int MINIMUM_MINUTES = 10;
|
||||
|
||||
@Comment("The channel IDs.\n"
|
||||
+ "The bot will need the \"View Channel\", \"Manage Channels\" and \"Connection\" permissions for the provided channels")
|
||||
public List<Long> channelIds = new ArrayList<>();
|
||||
@ -56,8 +59,9 @@ public class TimedUpdaterConfig {
|
||||
@Comment("The format for the channel name(s), placeholders are supported.")
|
||||
public String nameFormat = "";
|
||||
|
||||
@Comment("The time between updates in minutes. The minimum time is 10 minutes.")
|
||||
public int timeMinutes = 10;
|
||||
@Constants.Comment(intValue = MINIMUM_MINUTES)
|
||||
@Comment("The time between updates in minutes. The minimum time is %1 minutes.")
|
||||
public int timeMinutes = MINIMUM_MINUTES;
|
||||
|
||||
@Override
|
||||
public boolean any() {
|
||||
@ -71,12 +75,14 @@ public class TimedUpdaterConfig {
|
||||
|
||||
@Override
|
||||
public long minimumSeconds() {
|
||||
return TimeUnit.MINUTES.toSeconds(10);
|
||||
return TimeUnit.MINUTES.toSeconds(MINIMUM_MINUTES);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TextChannelConfig implements UpdaterConfig {
|
||||
|
||||
private static final int MINIMUM_MINUTES = 10;
|
||||
|
||||
@Comment("The channel IDs.\n"
|
||||
+ "The bot will need the \"View Channel\" and \"Manage Channels\" permissions for the provided channels")
|
||||
public List<Long> channelIds = new ArrayList<>();
|
||||
@ -89,8 +95,9 @@ public class TimedUpdaterConfig {
|
||||
+ "If this is blank, the topic will not be updated")
|
||||
public String topicFormat = "";
|
||||
|
||||
@Comment("The time between updates in minutes. The minimum time is 10 minutes.")
|
||||
public int timeMinutes = 10;
|
||||
@Constants.Comment(intValue = MINIMUM_MINUTES)
|
||||
@Comment("The time between updates in minutes. The minimum time is %1 minutes.")
|
||||
public int timeMinutes = MINIMUM_MINUTES;
|
||||
|
||||
@Override
|
||||
public boolean any() {
|
||||
@ -104,7 +111,7 @@ public class TimedUpdaterConfig {
|
||||
|
||||
@Override
|
||||
public long minimumSeconds() {
|
||||
return TimeUnit.MINUTES.toSeconds(10);
|
||||
return TimeUnit.MINUTES.toSeconds(MINIMUM_MINUTES);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user