Update bus API to fix an error
This commit is contained in:
parent
803370c35c
commit
1d5b113308
2 changed files with 38 additions and 45 deletions
|
@ -13,7 +13,14 @@ public class Bus {
|
|||
/**
|
||||
* The main event bus!
|
||||
*/
|
||||
private static Bus Main = new Bus("Main Event Bus", false);
|
||||
private static Bus Main;
|
||||
|
||||
static {
|
||||
if(Main == null)
|
||||
{
|
||||
Main = new Bus("Main Event Bus", false);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean debug = false;
|
||||
public final String BusName;
|
||||
|
@ -23,13 +30,7 @@ public class Bus {
|
|||
BusName = name;
|
||||
UsesInstances = useInstances;
|
||||
|
||||
try {
|
||||
Post(new EventBusReadyEvent());
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Post(new EventBusReadyEvent());
|
||||
}
|
||||
|
||||
public Map<Class<?>, List<EventContainer>> static_events = new HashMap<Class<?>, List<EventContainer>>();
|
||||
|
@ -95,31 +96,35 @@ public class Bus {
|
|||
* @param event The event you wish to post
|
||||
* @return True if the event was cancelled.
|
||||
*/
|
||||
public static boolean Post(Event event) throws InvocationTargetException, IllegalAccessException {
|
||||
public static boolean Post(Event event) {
|
||||
for (PriorityLevel level :
|
||||
PriorityLevel.values()) {
|
||||
// Call each priority level in order of declaration
|
||||
// Static first, then instanced
|
||||
// At the end, this method will return the cancellation result.
|
||||
try {
|
||||
|
||||
if (Main.static_events.containsKey(event.getClass())) {
|
||||
EventContainer[] tempArray = (EventContainer[]) Main.static_events.get(event.getClass()).toArray();
|
||||
if (Main.static_events.containsKey(event.getClass())) {
|
||||
EventContainer[] tempArray = (EventContainer[]) Main.static_events.get(event.getClass()).toArray();
|
||||
|
||||
for (EventContainer container : tempArray) {
|
||||
if (container.invoke(event, level)) {
|
||||
Main.static_events.get(event.getClass()).remove(container);
|
||||
for (EventContainer container : tempArray) {
|
||||
if (container.invoke(event, level)) {
|
||||
Main.static_events.get(event.getClass()).remove(container);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Main.instanced_events.containsKey(event.getClass())) {
|
||||
EventContainer[] tempArray = (EventContainer[]) Main.instanced_events.get(event.getClass()).toArray();
|
||||
if (Main.instanced_events.containsKey(event.getClass())) {
|
||||
EventContainer[] tempArray = (EventContainer[]) Main.instanced_events.get(event.getClass()).toArray();
|
||||
|
||||
for (EventContainer container : tempArray) {
|
||||
if (container.invoke(event, level)) {
|
||||
Main.instanced_events.get(event.getClass()).remove(container);
|
||||
for (EventContainer container : tempArray) {
|
||||
if (container.invoke(event, level)) {
|
||||
Main.instanced_events.get(event.getClass()).remove(container);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,18 +138,14 @@ public class Bus {
|
|||
* @see dev.zontreck.eventsbus.events.ResetEventBusEvent
|
||||
*/
|
||||
public static boolean Reset() {
|
||||
try {
|
||||
if (!Post(new ResetEventBusEvent())) {
|
||||
if (!Post(new ResetEventBusEvent())) {
|
||||
|
||||
Main.static_events = new HashMap<>();
|
||||
Main.instanced_events = new HashMap<>();
|
||||
Main.static_events = new HashMap<>();
|
||||
Main.instanced_events = new HashMap<>();
|
||||
|
||||
Post(new EventBusReadyEvent());
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
Post(new EventBusReadyEvent());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue