Skip to content

Commit

Permalink
add superclass checking to post
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigermouthbear committed Mar 6, 2022
1 parent 8bab083 commit af7a34b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/dev/tigr/simpleevents/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ public class EventManager {
* @return Event passed through
*/
public <T> T post(T event) {
Class<?> eventClass = event.getClass();
if(listenerMap.containsKey(eventClass)) listenerMap.get(eventClass).forEach(eventListener -> eventListener.invoke(event));
Class<?> clazz = event.getClass();
do {
if(listenerMap.containsKey(clazz)) {
for(EventListener listener: listenerMap.get(clazz))
listener.invoke(event);
}
} while((clazz = clazz.getSuperclass()) != Object.class);

return event;
}

Expand Down

0 comments on commit af7a34b

Please sign in to comment.