Fix up the event bus

This commit is contained in:
Aria 2023-03-13 02:45:18 -07:00
parent 54e60c6b2c
commit 5db113cbd3
2 changed files with 13 additions and 7 deletions

View file

@ -62,8 +62,14 @@ public class EventBus
public boolean post(Event event)
{
boolean cancelled = false;
for (Map.Entry<Class<?>, List<EventContainer>> entry : listeners.events.entrySet()) {
Class<?> eventClazz = entry.getKey();
for (Map.Entry<String, List<EventContainer>> entry : listeners.events.entrySet()) {
Class<?> eventClazz;
try {
eventClazz = Class.forName(entry.getKey());
} catch (ClassNotFoundException e) {
e.printStackTrace();
return false;
}
List<EventContainer> containers = entry.getValue();
if(eventClazz.isInstance(Event.class))

View file

@ -16,22 +16,22 @@ import com.google.common.collect.Maps;
public class EventsListenerList {
public Map<Class<?>, List<EventContainer>> events = Maps.newHashMap();
public Map<String, List<EventContainer>> events = Maps.newHashMap();
public void addEventMethod(Class<?> e, Method action, Class<?> clazz)
{
// Add a new container!
EventContainer contains = new EventContainer();
contains.function=action;
contains.containingClass = clazz;
if(!events.containsKey(e)){
if((events.entrySet().stream()
.filter(entry -> entry.getKey() == e.getName()).count()) == 0){
List<EventContainer> tmp = Lists.newArrayList();
tmp.add(contains);
events.put(e, tmp);
events.put(e.getName(), tmp);
}else {
events.get(e).add(contains);
events.get(e.getName()).add(contains);
}
}