Skip to content

Commit

Permalink
Implement new event hierarchy handling with ClassWalker (#1463)
Browse files Browse the repository at this point in the history
This changes the implementation of onEvent in ListenerAdapter to be more maintainable
  • Loading branch information
MinnDevelopment committed Dec 26, 2020
1 parent f2391d9 commit a52eae4
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 403 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

class GenericGuildVoiceUpdateEvent extends GenericGuildVoiceEvent implements GuildVoiceUpdateEvent
public class GenericGuildVoiceUpdateEvent extends GenericGuildVoiceEvent implements GuildVoiceUpdateEvent
{
protected final VoiceChannel joined, left;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package net.dv8tion.jda.api.hooks;

import net.dv8tion.jda.api.events.Event;
import net.dv8tion.jda.api.events.GenericEvent;
import net.dv8tion.jda.internal.JDAImpl;
import net.dv8tion.jda.internal.utils.ClassWalker;

import javax.annotation.Nonnull;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -80,11 +80,9 @@ public List<Object> getRegisteredListeners()
}

@Override
@SuppressWarnings("unchecked")
public void handle(@Nonnull GenericEvent event)
{
Class<?> eventClass = event.getClass();
do
for (Class<?> eventClass : ClassWalker.walk(event.getClass()))
{
Map<Object, List<Method>> listeners = methods.get(eventClass);
if (listeners != null)
Expand All @@ -108,9 +106,7 @@ public void handle(@Nonnull GenericEvent event)
}
}));
}
eventClass = eventClass == Event.class ? null : (Class<? extends GenericEvent>) eventClass.getSuperclass();
}
while (eventClass != null);
}

private void updateMethods()
Expand Down
Loading

0 comments on commit a52eae4

Please sign in to comment.