Skip to content

Commit 93c5a86

Browse files
committed
Split 2 duplicated methods to 1 private method
1 parent 2be248f commit 93c5a86

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

Diff for: src/main/java/at/jkvn/eventlib/EventLib.java

+8-15
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,26 @@ public class EventLib {
3232

3333
@SneakyThrows
3434
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);
4336
}
4437

4538
@SneakyThrows
4639
public static void callAsync(Event event) {
40+
executor.execute(() -> callEvent(event));
41+
}
42+
43+
private static void callEvent(Event event) {
4744
if (isAutomatic()) {
48-
invokeMethods(getMethods(), event, true);
45+
invokeMethods(getMethods(), event);
4946
return;
5047
}
5148

5249
(new ArrayList<>(listeners)).forEach(listener -> {
53-
invokeMethods(Arrays.stream(listener.getClass().getMethods()).toList(), event, true);
50+
invokeMethods(Arrays.stream(listener.getClass().getMethods()).toList(), event);
5451
});
5552
}
5653

57-
private static void invokeMethods(List<Method> methods, Event event, boolean async) {
54+
private static void invokeMethods(List<Method> methods, Event event) {
5855
methods.stream()
5956
.filter(method -> method.getParameterCount() == 1
6057
&& method.getParameterTypes()[0].isAssignableFrom(event.getClass()))
@@ -63,10 +60,6 @@ private static void invokeMethods(List<Method> methods, Event event, boolean asy
6360
return priority != null ? priority.value().ordinal() : EventPriority.NORMAL.ordinal();
6461
}))
6562
.forEach(method -> {
66-
if (async) {
67-
executor.execute(() -> invokeSafely(method, event));
68-
return;
69-
}
7063
invokeSafely(method, event);
7164
});
7265
}

0 commit comments

Comments
 (0)