Update bus API to fix an error

This commit is contained in:
zontreck 2023-11-19 03:14:38 -07:00
parent 803370c35c
commit 1d5b113308
2 changed files with 38 additions and 45 deletions

View file

@ -19,6 +19,8 @@ archivesBaseName = "EventsBus"
java { java {
toolchain.languageVersion = JavaLanguageVersion.of(17) toolchain.languageVersion = JavaLanguageVersion.of(17)
withSourcesJar()
withJavadocJar()
} }
def determinePatchVersion = { def determinePatchVersion = {
@ -52,25 +54,13 @@ dependencies {
def MAVEN_PASSWORD_PROPERTY = "AriasCreationsMavenPassword" def MAVEN_PASSWORD_PROPERTY = "AriasCreationsMavenPassword"
task sourcesJar (type: Jar) {
archiveClassifier = "sources"
from sourceSets.main.allJava
}
jar {
archiveClassifier = "final"
}
publishing { publishing {
publications { publications {
mavenJava(MavenPublication) { mavenJava(MavenPublication) {
from components.java from components.java
artifact (sourcesJar) { artifact jar
classifier = "sources" //artifact sourcesJar
} //artifact javadocJar
artifact (jar) {
classifier = "final"
}
} }
} }
repositories { repositories {
@ -89,7 +79,9 @@ publishing {
} }
compileJava.finalizedBy("sourcesJar") compileJava.finalizedBy("sourcesJar")
compileJava.finalizedBy("javadocJar")
artifacts { artifacts {
archives jar archives jar
archives sourcesJar archives sourcesJar
archives javadocJar
} }

View file

@ -13,7 +13,14 @@ public class Bus {
/** /**
* The main event 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 static boolean debug = false;
public final String BusName; public final String BusName;
@ -23,13 +30,7 @@ public class Bus {
BusName = name; BusName = name;
UsesInstances = useInstances; UsesInstances = useInstances;
try {
Post(new EventBusReadyEvent()); Post(new EventBusReadyEvent());
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
} }
public Map<Class<?>, List<EventContainer>> static_events = new HashMap<Class<?>, List<EventContainer>>(); public Map<Class<?>, List<EventContainer>> static_events = new HashMap<Class<?>, List<EventContainer>>();
@ -95,12 +96,13 @@ public class Bus {
* @param event The event you wish to post * @param event The event you wish to post
* @return True if the event was cancelled. * @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 : for (PriorityLevel level :
PriorityLevel.values()) { PriorityLevel.values()) {
// Call each priority level in order of declaration // Call each priority level in order of declaration
// Static first, then instanced // Static first, then instanced
// At the end, this method will return the cancellation result. // At the end, this method will return the cancellation result.
try {
if (Main.static_events.containsKey(event.getClass())) { if (Main.static_events.containsKey(event.getClass())) {
EventContainer[] tempArray = (EventContainer[]) Main.static_events.get(event.getClass()).toArray(); EventContainer[] tempArray = (EventContainer[]) Main.static_events.get(event.getClass()).toArray();
@ -121,6 +123,9 @@ public class Bus {
} }
} }
} }
} catch (Exception e) {
}
} }
return event.isCancelled(); return event.isCancelled();
@ -133,18 +138,14 @@ public class Bus {
* @see dev.zontreck.eventsbus.events.ResetEventBusEvent * @see dev.zontreck.eventsbus.events.ResetEventBusEvent
*/ */
public static boolean Reset() { public static boolean Reset() {
try {
if (!Post(new ResetEventBusEvent())) { if (!Post(new ResetEventBusEvent())) {
Main.static_events = new HashMap<>(); Main.static_events = new HashMap<>();
Main.instanced_events = new HashMap<>(); Main.instanced_events = new HashMap<>();
Post(new EventBusReadyEvent()); Post(new EventBusReadyEvent());
}
} catch (InvocationTargetException e) { return true;
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} }
return false; return false;