Skip to content

Commit

Permalink
refactor(events): Validate listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoenix-Starlight committed Mar 17, 2024
1 parent d6d0923 commit 2dff812
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/com/seailz/discordjar/events/EventDispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ public void addListener(DiscordListener... listeners) {
for (DiscordListener listener : listeners) {
for (Method method : listener.getClass().getMethods()) {
if (method.isAnnotationPresent(EventMethod.class)) {
Class<? extends Event> eventType = (Class<? extends Event>) method.getParameterTypes()[0];
Class<?> maybeEventType = method.getParameterTypes()[0];

if (!Event.class.isAssignableFrom(maybeEventType))
throw new IllegalArgumentException(String.format("%s first arg is not of Event", method));
else if (method.getParameterTypes().length > 1)
throw new IllegalArgumentException(String.format("%s#%s is an invalid listener", method.getDeclaringClass(), method.getName()));

@SuppressWarnings("unchecked")
Class<? extends Event> eventType = (Class<? extends Event>) maybeEventType;
EventMethod eventMethod = method.getAnnotation(EventMethod.class);

String customId = null;
Expand Down

0 comments on commit 2dff812

Please sign in to comment.