Fix comment constants, add error message, improve requirements comment

This commit is contained in:
Vankka 2024-01-01 16:45:00 +02:00
parent 4877235ace
commit 5279e09c33
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
4 changed files with 20 additions and 12 deletions

View File

@ -35,6 +35,7 @@ import com.discordsrv.common.config.main.channels.base.IChannelConfig;
import com.discordsrv.common.exception.ConfigException;
import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.logging.NamedLogger;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.configurate.*;
import org.spongepowered.configurate.loader.AbstractConfigurationLoader;
@ -55,6 +56,7 @@ import java.lang.reflect.Type;
import java.nio.file.Path;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public abstract class ConfigurateConfigManager<T, LT extends AbstractConfigurationLoader<CommentedConfigurationNode>>
implements ConfigManager<T>, ConfigLoaderProvider<LT> {
@ -213,11 +215,16 @@ public abstract class ConfigurateConfigManager<T, LT extends AbstractConfigurati
// This needs to go before comment processing.
if (commentSubstitutions && destination instanceof CommentedConfigurationNode) {
String comment = ((CommentedConfigurationNode) destination).comment();
if (comment != null) {
((CommentedConfigurationNode) destination).comment(
doSubstitution(comment, getValues(data.value(), data.intValue()))
if (StringUtils.isEmpty(comment)) {
logger.error(
Arrays.stream(destination.path().array()).map(Object::toString).collect(Collectors.joining(", "))
+ " is not commented but has comment constants! (make sure @Constants.Comment is below @Comment)"
);
return;
}
((CommentedConfigurationNode) destination).comment(
doSubstitution(comment, getValues(data.value(), data.intValue()))
);
}
})
.addProcessor(Constants.class, (data, fieldType) -> (value, destination) -> {

View File

@ -32,15 +32,15 @@ public class UpdateConfig {
public boolean notificationEnabled = true;
@Setting(value = "notification-ingame")
@Constants.Comment("discordsrv.updatenotification")
@Comment("If players with the %1 permission should receive\n"
+ "a update notification upon joining if there is a update available")
@Constants.Comment("discordsrv.updatenotification")
public boolean notificationInGame = true;
@Setting(value = "enable-first-party-api-for-notifications")
@Constants.Comment(UpdateChecker.DOWNLOAD_SERVICE_DOMAIN)
@Comment("Whether the DiscordSRV download API should be used for update checks\n"
+ "Requires a connection to: %1")
@Constants.Comment(UpdateChecker.DOWNLOAD_SERVICE_DOMAIN)
public boolean firstPartyNotification = true;
@Setting(value = "github")
@ -53,17 +53,17 @@ public class UpdateConfig {
public static class GitHub {
@Setting(value = "enabled")
@Constants.Comment(UpdateChecker.GITHUB_API_DOMAIN)
@Comment("Whether the GitHub API should be used for update checks\n"
+ "This will be the secondary API if both first party and GitHub sources are enabled\n"
+ "Requires a connection to: %1")
@Constants.Comment(UpdateChecker.GITHUB_API_DOMAIN)
public boolean enabled = true;
@Setting(value = "api-token")
@Constants.Comment(UpdateChecker.GITHUB_REPOSITORY)
@Comment("The GitHub API token used for authenticating to the GitHub api,\n"
+ "if this isn't specified the API will be used 'anonymously'\n"
+ "The token only requires read permission to %1 releases, workflows and commits")
@Constants.Comment(UpdateChecker.GITHUB_REPOSITORY)
public String apiToken = "";
}
@ -72,12 +72,12 @@ public class UpdateConfig {
public static class Security {
@Setting(value = "enabled")
@Constants.Comment(UpdateChecker.DOWNLOAD_SERVICE_DOMAIN)
@Comment("Uses the DiscordSRV download API to check if the version of DiscordSRV\n"
+ "being used is vulnerable to known vulnerabilities, disabling the plugin if it is.\n"
+ "Requires a connection to: %1\n"
+ "\n"
+ "WARNING! DO NOT TURN THIS OFF UNLESS YOU KNOW WHAT YOU'RE DOING AND STAY UP-TO-DATE")
@Constants.Comment(UpdateChecker.DOWNLOAD_SERVICE_DOMAIN)
public boolean enabled = true;
@Setting(value = "force")

View File

@ -59,8 +59,8 @@ public class TimedUpdaterConfig {
@Comment("The format for the channel name(s), placeholders are supported.")
public String nameFormat = "";
@Constants.Comment(intValue = MINIMUM_MINUTES)
@Comment("The time between updates in minutes. The minimum time is %1 minutes.")
@Constants.Comment(intValue = MINIMUM_MINUTES)
public int timeMinutes = MINIMUM_MINUTES;
@Override
@ -95,8 +95,8 @@ public class TimedUpdaterConfig {
+ "If this is blank, the topic will not be updated")
public String topicFormat = "";
@Constants.Comment(intValue = MINIMUM_MINUTES)
@Comment("The time between updates in minutes. The minimum time is %1 minutes.")
@Constants.Comment(intValue = MINIMUM_MINUTES)
public int timeMinutes = MINIMUM_MINUTES;
@Override

View File

@ -55,7 +55,8 @@ public class RequirementsConfig {
+ "\n"
+ "The following operators are available:\n"
+ "&& = and, for example: \"DiscordServer(...) && TwitchFollower()\"\n"
+ "|| = or, for example \"DiscordBoosting(...) || YouTubeMember()\n"
+ "You can also use brackets () to clear ambiguity, for example: \"DiscordServer(...) && (TwitchSubscriber() || PatreonSubscriber())\"")
+ "|| = or, for example \"DiscordBoosting(...) || YouTubeMember()\"\n"
+ "You can also use brackets () to clear ambiguity, for example: \"DiscordServer(...) && (TwitchSubscriber() || PatreonSubscriber())\"\n"
+ "allows a member of the specified Discord server that is also a twitch or patreon subscriber to join the server")
public List<String> requirements = new ArrayList<>();
}