Prioritize new Rule annotation when parsing if both are present

This commit is contained in:
altrisi committed 2023-04-03 21:58:16 +02:00
1 parent 50c22b6fe2
commit cda7f791b7
1 file changed
+4 -4
@@ -149,12 +149,12 @@ public final class ParsedRule<T> implements CarpetRule<T>, Comparable<ParsedRule
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public static <T> ParsedRule<T> of(Field field, SettingsManager settingsManager) { public static <T> ParsedRule<T> of(Field field, SettingsManager settingsManager) {
RuleAnnotation rule; RuleAnnotation rule;
if (settingsManager instanceof carpet.settings.SettingsManager && field.isAnnotationPresent(Rule.class)) { // Legacy path if (field.isAnnotationPresent(carpet.api.settings.Rule.class)) {
Rule a = field.getAnnotation(Rule.class);
rule = new RuleAnnotation(true, a.name(), a.desc(), a.extra(), a.category(), a.options(), a.strict(), a.appSource(), a.validate());
} else if (field.isAnnotationPresent(carpet.api.settings.Rule.class)) {
carpet.api.settings.Rule a = field.getAnnotation(carpet.api.settings.Rule.class); carpet.api.settings.Rule a = field.getAnnotation(carpet.api.settings.Rule.class);
rule = new RuleAnnotation(false, null, null, null, a.categories(), a.options(), a.strict(), a.appSource(), a.validators()); rule = new RuleAnnotation(false, null, null, null, a.categories(), a.options(), a.strict(), a.appSource(), a.validators());
} else if (settingsManager instanceof carpet.settings.SettingsManager && field.isAnnotationPresent(Rule.class)) { // Legacy path
Rule a = field.getAnnotation(Rule.class);
rule = new RuleAnnotation(true, a.name(), a.desc(), a.extra(), a.category(), a.options(), a.strict(), a.appSource(), a.validate());
} else { } else {
// Don't allow to use old rule types in custom AND migrated settings manager // Don't allow to use old rule types in custom AND migrated settings manager
throw new IllegalArgumentException("Old rule annotation is only supported in legacy SettngsManager!"); throw new IllegalArgumentException("Old rule annotation is only supported in legacy SettngsManager!");