Skip to content

Commit 65ee2cb

Browse files
committed
Add ConfigDataLong annotation and update AnnotationHandler to support it
1 parent 66326fc commit 65ee2cb

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

SimpleAPI/src/main/java/com/bencodez/simpleapi/file/annotation/AnnotationHandler.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,28 @@ public void load(ConfigurationSection config, Object classToLoad) {
8989

9090
field.set(classToLoad, value);
9191
}
92+
93+
ConfigDataLong longAnnotation = field.getAnnotation(ConfigDataLong.class);
94+
if (longAnnotation != null) {
95+
long defaultValue = longAnnotation.defaultValue();
96+
if (defaultValue == 0) {
97+
try {
98+
int v = field.getInt(classToLoad);
99+
defaultValue = v;
100+
} catch (Exception e) {
101+
102+
}
103+
}
104+
long value = 0;
105+
if (!longAnnotation.secondPath().isEmpty()) {
106+
value = config.getLong(longAnnotation.path(),
107+
config.getLong(longAnnotation.secondPath(), defaultValue));
108+
} else {
109+
value = config.getLong(longAnnotation.path(), defaultValue);
110+
}
111+
112+
field.set(classToLoad, value);
113+
}
92114

93115
ConfigDataDouble doubleAnnotation = field.getAnnotation(ConfigDataDouble.class);
94116
if (doubleAnnotation != null) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.bencodez.simpleapi.file.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Inherited;
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
import java.lang.annotation.Target;
8+
9+
@Inherited
10+
@Target({ ElementType.METHOD, ElementType.FIELD })
11+
@Retention(RetentionPolicy.RUNTIME)
12+
public @interface ConfigDataLong {
13+
long defaultValue() default 0;
14+
15+
String[] options() default "";
16+
17+
String path();
18+
19+
String secondPath() default "";
20+
}

0 commit comments

Comments
 (0)