Skip to content

Commit 7dfb3a2

Browse files
committed
Update EventUtil for 1.21.5+
1 parent 223b432 commit 7dfb3a2

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

paper/src/main/java/org/incendo/interfaces/paper/utils/EventUtil.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@
99
@DefaultQualifier(NonNull.class)
1010
public final class EventUtil {
1111

12+
private static final Field EVENT_IS_ASYNC_FIELD;
13+
14+
static {
15+
Field field;
16+
try {
17+
try {
18+
field = Event.class.getDeclaredField("async");
19+
} catch (final NoSuchFieldException e0) {
20+
try {
21+
field = Event.class.getDeclaredField("isAsync");
22+
} catch (final NoSuchFieldException e1) {
23+
e1.addSuppressed(e0);
24+
throw e1;
25+
}
26+
}
27+
field.setAccessible(true);
28+
} catch (final Throwable thr) {
29+
throw new RuntimeException("Failed to find async/isAsync field in Event class", thr);
30+
}
31+
EVENT_IS_ASYNC_FIELD = field;
32+
}
33+
1234
private EventUtil() {
1335
}
1436

@@ -20,9 +42,7 @@ private EventUtil() {
2042
*/
2143
public static void setAsync(final Event event, final boolean async) {
2244
try {
23-
final Field field = Event.class.getDeclaredField("async");
24-
field.setAccessible(true);
25-
field.set(event, async);
45+
EVENT_IS_ASYNC_FIELD.set(event, async);
2646
} catch (final ReflectiveOperationException ex) {
2747
throw new RuntimeException(ex);
2848
}

0 commit comments

Comments
 (0)