Skip to content

Commit

Permalink
Merge pull request #280 from Phoenix-Starlight/refactor/validate-even…
Browse files Browse the repository at this point in the history
…t-listeners
  • Loading branch information
seailz authored Mar 22, 2024
2 parents d6d0923 + 47b5a99 commit b0285cc
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 b0285cc

Please sign in to comment.