@@ -32,29 +32,26 @@ public class EventLib {
32
32
33
33
@ SneakyThrows
34
34
public static void call (Event event ) {
35
- if (isAutomatic ()) {
36
- invokeMethods (getMethods (), event , false );
37
- return ;
38
- }
39
-
40
- (new ArrayList <>(listeners )).forEach (listener -> {
41
- invokeMethods (Arrays .stream (listener .getClass ().getMethods ()).toList (), event , false );
42
- });
35
+ callEvent (event );
43
36
}
44
37
45
38
@ SneakyThrows
46
39
public static void callAsync (Event event ) {
40
+ executor .execute (() -> callEvent (event ));
41
+ }
42
+
43
+ private static void callEvent (Event event ) {
47
44
if (isAutomatic ()) {
48
- invokeMethods (getMethods (), event , true );
45
+ invokeMethods (getMethods (), event );
49
46
return ;
50
47
}
51
48
52
49
(new ArrayList <>(listeners )).forEach (listener -> {
53
- invokeMethods (Arrays .stream (listener .getClass ().getMethods ()).toList (), event , true );
50
+ invokeMethods (Arrays .stream (listener .getClass ().getMethods ()).toList (), event );
54
51
});
55
52
}
56
53
57
- private static void invokeMethods (List <Method > methods , Event event , boolean async ) {
54
+ private static void invokeMethods (List <Method > methods , Event event ) {
58
55
methods .stream ()
59
56
.filter (method -> method .getParameterCount () == 1
60
57
&& method .getParameterTypes ()[0 ].isAssignableFrom (event .getClass ()))
@@ -63,11 +60,9 @@ private static void invokeMethods(List<Method> methods, Event event, boolean asy
63
60
return priority != null ? priority .value ().ordinal () : EventPriority .NORMAL .ordinal ();
64
61
}))
65
62
.forEach (method -> {
66
- if (async ) {
67
- executor .execute (() -> invokeSafely (method , event ));
68
- return ;
63
+ if (!event .isCancelled ()) {
64
+ invokeSafely (method , event );
69
65
}
70
- invokeSafely (method , event );
71
66
});
72
67
}
73
68
0 commit comments