Skip to content

Commit 4cae3c1

Browse files
committed
fix field-type accordions
1 parent 71f2fbc commit 4cae3c1

2 files changed

Lines changed: 5 additions & 13 deletions

File tree

modules/config-impl/src/main/java/org/polyfrost/oneconfig/api/config/v1/annotations/Button.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
@Option(display = Visualizer.ButtonVisualizer.class)
3434
@Retention(RetentionPolicy.RUNTIME)
35-
@Target({ElementType.FIELD, ElementType.METHOD})
35+
@Target(ElementType.METHOD)
3636
@Documented
3737
public @interface Button {
3838
String title();

modules/config-impl/src/main/java/org/polyfrost/oneconfig/api/config/v1/collect/impl/OneConfigCollector.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ protected void handleField(@NotNull Field f, @NotNull Object src, @NotNull Tree
8181
continue;
8282
}
8383
if (type == Accordion.class) {
84-
Tree t = Tree.tree(f.getName());
85-
t.addMetadata(MHUtils.getAnnotationValues(a).getOrThrow());
8684
try {
85+
Tree t = Tree.tree(f.getName());
86+
t.addMetadata(MHUtils.getAnnotationValues(a).getOrThrow());
8787
handle(t, MHUtils.instantiate(f.getType(), true).getOrThrow(), 1);
88+
tree.put(t);
8889
} catch (Throwable e) {
8990
throw new RuntimeException("Failed to collect accordion-type field " + f.getName(), e);
9091
}
@@ -93,16 +94,7 @@ protected void handleField(@NotNull Field f, @NotNull Object src, @NotNull Tree
9394
Option opt = type.getDeclaredAnnotation(Option.class);
9495
if (opt == null) continue;
9596
try {
96-
Property<?> p;
97-
if (type == Button.class) {
98-
p = Properties.dummy();
99-
try {
100-
p.addMetadata("runnable", (Runnable) MHUtils.setAccessible(f).get(src));
101-
} catch (Throwable e) {
102-
throw new RuntimeException("Couldn't extract button method from field " + f.getName() + ", is it of type Runnable?", e);
103-
}
104-
}
105-
else p = Properties.field(null, null, f, src);
97+
Property<?> p = Properties.field(null, null, f, src);
10698
handleMetadata(tree, p, a, opt, f);
10799
tree.put(p);
108100
} catch (Throwable e) {

0 commit comments

Comments
 (0)